本文整理汇总了C#中SemplestModel.Semplest.SaveChanges方法的典型用法代码示例。如果您正苦于以下问题:C# Semplest.SaveChanges方法的具体用法?C# Semplest.SaveChanges怎么用?C# Semplest.SaveChanges使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SemplestModel.Semplest
的用法示例。
在下文中一共展示了Semplest.SaveChanges方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
public ActionResult Create(BillType billtype)
{
try
{
using (var db = new SemplestModel.Semplest())
{
db.BillTypes.Add(billtype);
db.SaveChanges();
}
return RedirectToAction("BillType");
}
catch
{
return View();
}
}
示例2: ContactUs
public ActionResult ContactUs(SEMCustomerDetail model)
{
if (ModelState.IsValid && !(model.CallMe == false && model.EmailMe == false))
{
try
{
model.CreatedDate = DateTime.Now;
using (var dbContext = new SemplestModel.Semplest())
{
string semEmail = dbContext.Configurations.Select(m => m.DefalutEmailContactMe).FirstOrDefault();
if (model.EmailMe == false)
{
model.email = "";
}
else if (model.CallMe == false)
{
model.Phone = "";
}
dbContext.SEMCustomerDetails.Add(model);
dbContext.SaveChanges();
// send email using smtp server
if (model.EmailMe == true)
SendMail(model, semEmail);
}
}
catch (Exception ex)
{
string errMsg = "Error: " + ex.Message + "\r\n" + ex.StackTrace;
var errModel = new ErrorModel() { MsgToLog = errMsg, MsgToShow = "Error" };
return View("ErrorPage", errModel);
}
return RedirectToAction("ThankYou");
}
else
{
return View(model);
}
}
示例3: SaveSiteLinks
public void SaveSiteLinks(CampaignSetupModel model, int customerFk, CampaignSetupModel oldModel)
{
bool shouldRefreshSiteLinks = false;
using (var dbcontext = new SemplestModel.Semplest())
{
var queryProd = (from c in dbcontext.ProductGroups
where
c.CustomerFK == customerFk &&
c.ProductGroupName == model.ProductGroup.ProductGroupName
select c).Single();
var promo = GetPromotionFromProductGroup(queryProd, model.ProductGroup.ProductPromotionName);
List<GoogleSiteLink> sl =
model.SiteLinks.Where(t => !t.Delete).Select(row => new GoogleSiteLink
{
LinkText = row.LinkText,
LinkURL = row.LinkURL
}).ToList();
if (sl.Any())
{
GoogleViolation[] gv = ValidateSiteLinks(sl);
if (gv.Length > 0)
throw new Exception(gv.First().shortFieldPath + ": " + gv.First().errorMessage);
}
shouldRefreshSiteLinks = AddSiteLinksToPromotion(promo, model, customerFk, ((IObjectContextAdapter)dbcontext).ObjectContext, oldModel);
dbcontext.SaveChanges();
_savedCampaign = true;
try
{
var adEngines = new List<string>();
if (promo.IsLaunched && shouldRefreshSiteLinks)
{
adEngines.AddRange(
promo.PromotionAdEngineSelecteds.Select(pades => pades.AdvertisingEngine.AdvertisingEngine1));
var sw = new ServiceClientWrapper();
sw.scheduleRefreshSiteLinks(promo.PromotionPK, adEngines);
}
}
catch (Exception ex)
{
SharedResources.Helpers.ExceptionHelper.LogException(ex);
}
}
}
示例4: Upload
//.........这里部分代码省略.........
dbcontext.Phones.Add(ph);
var cpa = new CustomerPhoneAssociation { Customer = c, Phone = ph };
dbcontext.CustomerPhoneAssociations.Add(cpa);
StateCode sc = dbcontext.StateCodes.First(p => p.StateAbbr == m.State);
AddressType at = dbcontext.AddressTypes.First(p => p.AddressType1 == "H"); // --- address types --- !!!
var a = new Address { Address1 = m.Address1, Address2 = m.Address2, City = m.City, ZipCode = m.Zip, StateCode = sc };
dbcontext.Addresses.Add(a);
var caa = new CustomerAddressAssociation { Address = a, Customer = c, AddressType = at };
dbcontext.CustomerAddressAssociations.Add(caa);
var cn = new CustomerNote { Customer = c, Note = m.CustomerNote };
dbcontext.CustomerNotes.Add(cn);
var r = dbcontext.Roles.First(p => p.RolePK == imp.SelectedRoleID);
var ura = new UserRolesAssociation { Role = r, User = u };
dbcontext.UserRolesAssociations.Add(ura);
//default to the parent's rep and salesperson
var parentrepandsales = (from prs in dbcontext.EmployeeCustomerAssociations
where prs.CustomerFK.Equals(imp.ParentID)
select prs).ToList();
foreach (EmployeeCustomerAssociation eca in parentrepandsales)
{
var addrepandsales = new EmployeeCustomerAssociation { Customer = c, EmployeeFK = eca.EmployeeFK };
dbcontext.EmployeeCustomerAssociations.Add(addrepandsales);
}
//add child to parent in customerhierarchy
var ch = new CustomerHierarchy { CustomerFK = c.CustomerPK, CustomerParentFK = imp.ParentID };
dbcontext.CustomerHierarchies.Add(ch);
dbcontext.SaveChanges();
if (fc["sendcustomeremail"] != null)
{
///////////////////////////////////////////////////////////////
//FOR SENDING OUT EMAILS to child customers
/// /// /// /// /// /// /// /// /// /// /// /// /// /// /// ///
var parentdetails = from usr in dbcontext.Users
join cus in dbcontext.Customers on usr.CustomerFK equals cus.CustomerPK
where usr.CustomerFK == imp.ParentID
select new { usr.CustomerFK, usr.Email, cus.Name };
//send mail //revisit
string from = "[email protected]";
string to = u.Email;
string body = emailtemplate.EmailBody;
string subject = emailtemplate.EmailSubject;
body = body.Replace("[ChildCustomerFirstLast]", u.FirstName.ToString() + " " + u.LastName.ToString());
body = body.Replace("[ParentCustomerName]", parentdetails.FirstOrDefault().Name.ToString());
body = body.Replace("[FAQs]", "http://faq");
body = body.Replace("[ChildCustomerUserID]", cr.Username.ToString());
body = body.Replace("[ChildCustomerPassword]", cr.Password.ToString());
body = body.Replace("[INSERT LINK]", "http://encrypto");
//SendEmail
bool sent = false;
ServiceClientWrapper scw = new ServiceClientWrapper();
sent = scw.SendEmail(subject, from, to, body);
}
}
示例5: LogIn
public ActionResult LogIn(Semplest.SharedResources.Models.ProfileModel pm, string ReturnUrl, string isAdmin, FormCollection f)
{
if (ModelState.IsValid)
{
ModelState.Clear();
Dictionary<string, int> loginHash = (Dictionary<string, int>)Session[Semplest.SharedResources.SEMplestConstants.SESSION_LOGINATTEMPTS];
if (loginHash == null)
{
loginHash = new Dictionary<string, int>();
loginHash.Add(pm.UserName, 1);
}
else if (loginHash.ContainsKey(pm.UserName))
loginHash[pm.UserName] += 1;
else
loginHash.Add(pm.UserName, 1);
Session[Semplest.SharedResources.SEMplestConstants.SESSION_LOGINATTEMPTS] = loginHash;
bool isAdminLogin = isAdmin == null ? false : true;
using (var dbContext = new SemplestModel.Semplest())
{
Credential cred = null;
if (Session[Semplest.SharedResources.SEMplestConstants.SESSION_USERID] != null)
{
cred = (Credential)Session[Semplest.SharedResources.SEMplestConstants.SESSION_USERID];
}
else
{
IQueryable<Credential> creds = null;
if(pm.LoggedInSucceeded)
creds = dbContext.Credentials.Where(c => c.Username == pm.UserName);
else
creds = dbContext.Credentials.Where(c => c.Username == pm.UserName && c.Password == pm.Password1);
if (creds.Count() == 1)
{
if ((isAdminLogin && creds.First().IsAdmin()) || (!isAdminLogin && !creds.First().IsAdmin()))
cred = creds.First();
}
}
if (cred == null)
{
pm.LoggedInSucceeded = false;
if (loginHash[pm.UserName] > 3)
{
var userCreds = dbContext.Credentials.Where(c => c.Username == pm.UserName);
if (userCreds.Count() > 0 && userCreds.First().User.IsActive)
{
userCreds.First().User.IsActive = false;
dbContext.SaveChanges();
}
pm.LoginFailedMessage = "Sorry, your account is currently locked. To enable your account, please email [email protected] for assistance. Thank you!";
}
else
pm.LoginFailedMessage = "The user name or password entered is incorrect. Please try again.";
}
else if (!cred.User.IsActive)
{
pm.LoggedInSucceeded = false;
pm.LoginFailedMessage = "Sorry, your account is currently locked. To enable your account, please email [email protected] for assistance. Thank you!";
}
else
{
Session[Semplest.SharedResources.SEMplestConstants.SESSION_USERID] = cred;
if (cred.User.IsRegistered)
{
//if the user doesn't have a parent in the customerparentfk column then they are a parent else they are a child
//if (cred.User.CustomerFK == null || string.IsNullOrEmpty(cred.User.Customer.CustomerHierarchies.First().CustomerParentFK.ToString()))
// return RedirectToAction("Index", "Home");
//else if (cred.User.IsRegistered)
//user is a regular core user
if (cred.User.CustomerFK == null)
return RedirectToAction("Index", "Home");
else
return RedirectToAction("Index2", "Home");
}
else if (pm.LoggedInSucceeded)
{
Credential saveCred = dbContext.Credentials.Where(x => x.Username == cred.Username && x.Password == cred.Password).First();
//authenticated properly and submitted secondary form SecurityAnswer/SecurityQuestion
saveCred.SecurityAnswer = pm.SecurityAnswer;
saveCred.SecurityQuestion = pm.SecurityQuestion;
saveCred.Password = pm.Password2;
saveCred.User.IsRegistered = true;
int i = dbContext.SaveChanges();
return RedirectToAction("Index", "Home");
}
else
{
//authenticated properly and HAS NOT submitted secondary form SecurityAnswer/SecurityQuestion to complete registration
pm.IsRegistered = false;
pm.LoggedInSucceeded = true;
}
}
}
}
return View(pm);
}
示例6: LaunchAdProduct
public ActionResult LaunchAdProduct(CampaignSetupModel model)
{
try
{
var dbContext = new SemplestModel.Semplest();
var cr = new CreditCardRepository(dbContext);
var sr = new StateRepository(dbContext);
var pr = new PromotionRepository(dbContext);
var bt = new BillTypeRepository(dbContext);
var promo = pr.GetPromoitionFromCampaign(GetCustomerId(), model.ProductGroup.ProductGroupName,
model.ProductGroup.ProductPromotionName);
var retVal = new ReturnState(false,false,"Not a credit card customer", null);
if (model.BillType == bt.GetBillTypeCode("Credit Card"))
{
retVal = cr.ChargeCreditCard(new CustomerObject
{
Address1 = model.BillingLaunch.Address,
City = model.BillingLaunch.City,
Email = model.BillingLaunch.Email,
StateAbbr =
sr.GetStateNameFromCode(
int.Parse(model.BillingLaunch.StateCodeFK)),
ExpireDateMMYY =
model.BillingLaunch.ExpiryMonth +
model.BillingLaunch.ExpiryYear,
FirstName = model.BillingLaunch.FirstName,
LastName = model.BillingLaunch.LastName,
Phone = model.BillingLaunch.Phone,
ZipCode = model.BillingLaunch.Zip,
creditCardNumber = model.BillingLaunch.CardNumber
}, promo, model.BillType, model.ProductGroup.Budget);
}
try
{
if (!retVal.IsException && !retVal.IsValidationError)
{
dbContext.SaveChanges();
var adEngines = new List<string>();
adEngines.AddRange(
promo.PromotionAdEngineSelecteds.Select(
pades => pades.AdvertisingEngine.AdvertisingEngine1));
var sw = new ServiceClientWrapper();
if (sw.ScheduleAddPromotionToAdEngine(GetCustomerId(), promo.ProductGroupFK,
promo.PromotionPK, adEngines.ToArray()))
{
pr.SetPromotionToLaunched(promo.PromotionPK);
dbContext.SaveChanges();
}
return Json(retVal.ReturnMessage);
}
}
catch (Exception ex)
{
ExceptionHelper.LogException(ex);
return Json(retVal.ReturnMessage);
}
if (!retVal.IsException && retVal.IsValidationError)
return Json("Validation Error<~> " + retVal.ReturnMessage);
}
catch (Exception ex)
{
ExceptionHelper.LogException(ex);
}
return Json(ConfigurationManager.AppSettings["TechnicalDifficulties"]);
}
示例7: Add
//.........这里部分代码省略.........
dbcontext.CustomerNotes.Add(cn);
//don't add if not assigned
if (m.SelectedRepID != -1)
{
var addrep = new EmployeeCustomerAssociation { Customer = c, EmployeeFK = m.SelectedRepID };
dbcontext.EmployeeCustomerAssociations.Add(addrep);
}
//don't add if not assigned
if (m.SelectedSalesPersonID != -1)
{
var addsales = new EmployeeCustomerAssociation { Customer = c, EmployeeFK = m.SelectedSalesPersonID };
dbcontext.EmployeeCustomerAssociations.Add(addsales);
}
CustomerHierarchy ch = null;
if (m.SelectedParentID == -1) //set parent
{
ch = new CustomerHierarchy {CustomerFK = c.CustomerPK, CustomerParentFK = null};
dbcontext.CustomerHierarchies.Add(ch);
}
else if (m.SelectedParentID == 0) //set self -- single user
{
ch = new CustomerHierarchy {CustomerFK = c.CustomerPK, CustomerParentFK = c.CustomerPK};
dbcontext.CustomerHierarchies.Add(ch);
}
else //assign a parent
{
ch = new CustomerHierarchy {CustomerFK = c.CustomerPK, CustomerParentFK = m.SelectedParentID};
dbcontext.CustomerHierarchies.Add(ch);
}
dbcontext.SaveChanges();
/////////////////////////////////////////////////////////////////////////////
///// sending of emails
AesEncyrption ae = AesEncyrption.getInstance();
string encryptedToken = ae.GenerateToken(ch.CustomerParentFK.Value.ToString(), DateTime.Now.ToString(), cr.Username, cr.Password);
string emailUrl = System.Configuration.ConfigurationManager.AppSettings["VerificationUrl"].ToString() + encryptedToken;
if (fc["sendcustomeremail"] != null)
{
string from, to, body, subject;
//send email to child customers
//if child customer
if (m.SelectedParentID >0)
{
var emailtemplate = (
from et in dbcontext.EmailTemplates
join ey in dbcontext.EmailTypes on et.EmailTypeFK equals ey.EmailTypePK
where ey.EmailType1.Equals("WelcomeEmailChild")
select et).FirstOrDefault();
var parentdetails = from usr in dbcontext.Users
join cus in dbcontext.Customers on usr.CustomerFK equals cus.CustomerPK
where usr.CustomerFK == m.SelectedParentID
select new { usr.CustomerFK, usr.Email, cus.Name };
//send mail //revisit
from = "[email protected]";
to = u.Email;
body = emailtemplate.EmailBody;
//parent name in subject line
subject = parentdetails.FirstOrDefault().Name + " " +emailtemplate.EmailSubject;
body = body.Replace("[ChildCustomerFirstLast]", u.FirstName.ToString() + " " + u.LastName.ToString());
示例8: MyProfile
public ActionResult MyProfile(ChildModel m, string command)
{
if (command.ToLower() == "cancel") return RedirectToAction("Index2", "Home");
//if (command.ToLower() == "delete")
SemplestModel.Semplest dbcontext = new SemplestModel.Semplest();
//check if userid has been taken by other users
var userIDSs = from c in dbcontext.Credentials
where c.Username.Equals(m.UserID) && !c.UsersFK.Equals(m.UserPK)
select c;
if (userIDSs.Count() > 0)
ModelState.AddModelError("UserID", "This UserID is already taken!!");
if (!ModelState.IsValid)
{
var allstates = (from sc in dbcontext.StateCodes select sc).ToList();
m.States = allstates.Select(r => new SelectListItem
{
Value = r.StateAbbrPK.ToString(),
Text = r.StateAbbr.ToString()
});
return View(m);
}
var user = dbcontext.Users.ToList().Find(p => p.UserPK == m.UserPK);
user.FirstName = m.FirstName;
user.LastName = m.LastName;
user.MiddleInitial = m.MiddleInitial;
user.Email = m.Email;
user.EditedDate = DateTime.Now;
//UpdateModel(user);
var customer = dbcontext.Customers.ToList().Find(p => p.CustomerPK == m.AccountNumber);
var customeraddressassociation = dbcontext.CustomerAddressAssociations.ToList().Find(p => p.CustomerFK == customer.CustomerPK);
var address = dbcontext.Addresses.ToList().Find(p => p.AddressPK == customeraddressassociation.AddressFK);
customer.Name = m.Customer;
customer.InternalCustomerId = m.internalID;
UpdateModel(customer);
address.Address1 = m.Address1;
address.Address2 = m.Address2;
address.City = m.City;
address.ZipCode = m.Zip;
address.EditedDate = DateTime.Now;
address.StateAbbrFK = m.SelectedStateID;
UpdateModel(address);
var customerphoneassociation = dbcontext.CustomerPhoneAssociations.ToList().Find(p => p.CustomerFK == m.AccountNumber);
var phone = dbcontext.Phones.ToList().Find(p => p.PhonePK == customerphoneassociation.PhoneFK);
phone.Phone1 = m.Phone;
UpdateModel(phone);
var credentials = dbcontext.Credentials.ToList().Find(p => p.UsersFK == m.UserPK);
credentials.Username = m.UserID;
credentials.Password = m.UserPassword;
credentials.SecurityQuestion = m.SecurityQuestion;
credentials.SecurityAnswer = m.SecurityAnswer;
UpdateModel(credentials);
dbcontext.SaveChanges();
return RedirectToAction("Index2","Home");
//return View("index");
//return View(m);
}
示例9: AddProductGroupName
public ActionResult AddProductGroupName(FormCollection fc)
{
try
{
string productgroupname = fc["newproductgroupname"].ToString().Trim();
Credential c = ((Credential)(Session[Semplest.SharedResources.SEMplestConstants.SESSION_USERID]));
if (productgroupname == null || productgroupname == "") throw new Exception("Blank");
SemplestModel.Semplest dbContext = new SemplestModel.Semplest();
var productgroupexists = from pg in dbContext.ProductGroups
where pg.CustomerFK.Equals(c.User.CustomerFK.Value) && pg.ProductGroupName.Equals(productgroupname)
select pg;
if (productgroupexists.Count() > 0) throw new Exception("Duplicate");
dbContext.ProductGroups.Add(new ProductGroup { CustomerFK = c.User.CustomerFK.Value, ProductGroupName = productgroupname, StartDate = DateTime.Now, IsActive = true });
dbContext.SaveChanges();
}
catch (Exception ex)
{
}
return RedirectToAction("Index2");
}
示例10: Delete
//.........这里部分代码省略.........
var customerstyle = dbcontext.CustomerStyles.ToList().Find(p => p.CustomerFK.Equals(m.CustomerAccount.AccountNumber));
var customerphoneassociation = dbcontext.CustomerPhoneAssociations.ToList().Find(p => p.CustomerFK.Equals(m.CustomerAccount.AccountNumber));
var phone = dbcontext.Phones.ToList().Find(p => p.PhonePK.Equals(customerphoneassociation.PhoneFK));
var credentials = dbcontext.Credentials.ToList().Find(p => p.UsersFK.Equals(m.CustomerAccount.UserPK));
var userrolesassociation = dbcontext.UserRolesAssociations.ToList().Find(p => p.UsersFK.Equals(m.CustomerAccount.UserPK));
var customerhierarchy = dbcontext.CustomerHierarchies.ToList().Find(p => p.CustomerFK.Equals(m.CustomerAccount.AccountNumber));
var productgroup = dbcontext.ProductGroups.ToList().Find(p => p.CustomerFK.Equals(customer.CustomerPK));
if (productgroup != null) throw new Exception("Could not delete customer");
//UPDATE: no need to check for promotion, won't be deleting any customer that has a productgroup assigned!!!
//var promotion = dbcontext.Promotions.ToList().Find(p => p.ProductGroupFK.Equals(productgroup.ProductGroupPK));
//if (promotion != null) throw new Exception("Could not delete customer");
//Message = "The operation failed: The relationship could not be changed because one or more of the foreign-key properties is non-nullable. When a change is made to a relationship, the related foreign-key property is set to a null value. If the foreign-key does not sup...
//dbcontext.Customers.Remove(customer);
//dbcontext.Users.Remove(user);
//dbcontext.EmployeeCustomerAssociations.Remove(employeecustomerassociation);
//if (customerstyle!=null)
// dbcontext.CustomerStyles.Remove(customerstyle);
//dbcontext.CustomerPhoneAssociations.Remove(customerphoneassociation);
//dbcontext.Phones.Remove(phone);
//dbcontext.Credentials.Remove(credentials);
//if(userrolesassociation!=null)
// dbcontext.UserRolesAssociations.Remove(userrolesassociation);
//workaround for deletion:
var caa = customeraddressassociation;
var a = address;
var cn = customernotes;
dbcontext.CustomerAddressAssociations.Remove(caa);
dbcontext.Addresses.Remove(a);
dbcontext.CustomerNotes.Remove(cn);
//EmployeeCustomerAssociation eca = employeecustomerassociation;
//dbcontext.EmployeeCustomerAssociations.Remove(eca);
foreach (EmployeeCustomerAssociation c1 in employeecustomerassociation)
{
if (c1.CustomerFK.Equals(m.CustomerAccount.AccountNumber))
{
dbcontext.EmployeeCustomerAssociations.Remove(c1);
}
}
var c = customer;
dbcontext.Customers.Remove(c);
var cr = credentials;
dbcontext.Credentials.Remove(cr);
var u = user;
dbcontext.Users.Remove(u);
var cpa = customerphoneassociation;
dbcontext.CustomerPhoneAssociations.Remove(cpa);
var ph = phone;
dbcontext.Phones.Remove(ph);
if (customerstyle != null)
{
var cs = customerstyle;
dbcontext.CustomerStyles.Remove(cs);
}
if (userrolesassociation != null)
{
var ura = userrolesassociation;
dbcontext.UserRolesAssociations.Remove(ura);
}
var ch = customerhierarchy;
dbcontext.CustomerHierarchies.Remove(ch);
dbcontext.SaveChanges();
TempData["message"] = "Customer Account #" + m.CustomerAccount.AccountNumber + " (" + m.CustomerAccount.Customer + ") has been successfully deleted.";
}
catch (Exception ex)
{
TempData["message"] = "Customer Account #" + m.CustomerAccount.AccountNumber + " (" + m.CustomerAccount.Customer + ") could NOT be deleted.";
}
}
//return View();
return RedirectToAction("Index");
}
示例11: Add
//.........这里部分代码省略.........
List<SelectListItem> sli = new List<SelectListItem>();
sli.Add(new SelectListItem { Value = (-1).ToString(), Text = "«« Not Assigned »»" });
m.ReportingTo = reportingto.Select(r => new SelectListItem
{
Value = r.EmployeePK.ToString(),
Text = r.FirstName.ToString() + " " + r.LastName.ToString()
}).Union(sli);
/////////////////////////////////////////////////////////////////////////////////
// for employeetype dropdown
/////////////////////////////////////////////////////////////////////////////////
var employeetypes = (from r in dbcontext.EmployeeTypes select r).ToList();
m.EmployeeTypes = employeetypes.Select(r => new SelectListItem
{
Value = r.EmployeeTypeID.ToString(),
Text = r.EmployeeType1.ToString()
});
return View(m);
}
try
{
var u = new User
{
Customer = null,
Email = m.EmployeeSetup.Email,
FirstName = m.EmployeeSetup.FirstName,
MiddleInitial = m.EmployeeSetup.MiddleInitial,
LastName = m.EmployeeSetup.LastName,
CustomerFK = null,
IsActive = m.EmployeeSetup.isActive,
IsRegistered = true //only for admin, force registered=true (Andre)
};
dbcontext.Users.Add(u);
var r= dbcontext.Roles.First(p => p.RolePK == m.SelectedRoleID );
var ura = new UserRolesAssociation {Role = r, User = u};
dbcontext.UserRolesAssociations.Add(ura);
var et = dbcontext.EmployeeTypes.First(p => p.EmployeeTypeID == m.SelectedEmployeeTypeID);
var e = new Employee {EmployeeType = et, User = u, HireDate = m.EmployeeSetup.HireDate};
dbcontext.Employees.Add(e);
//Credential c = dbcontext.Credentials.Add(new Credential { User = u, Username = m.EmployeeSetup.Email, Password = "t" });
var cr = new Credential
{
User = u,
UsersFK = u.UserPK,
Username = m.EmployeeSetup.UserID,
Password = m.EmployeeSetup.UserPassword
};
dbcontext.Credentials.Add(cr);
//BillType bt = dbcontext.BillTypes.First(p => p.BillType1 == "Flat Fee"); // --- feees --- !!!
//ProductGroupCycleType pgct = dbcontext.ProductGroupCycleTypes.First(p => p.ProductGroupCycleType1 == "Product Group Cycle 30");
//Customer c = dbcontext.Customers.Add(new Customer { Name = m.CustomerAccount.Customer, BillType = bt, ProductGroupCycleType = pgct });
//User u = dbcontext.Users.Add(new User
//{
// Customer = c,
// Email = m.CustomerAccount.Email,
// FirstName = m.CustomerAccount.FirstName,
// LastName = m.CustomerAccount.LastName
//});
//Credential cr = dbcontext.Credentials.Add(new Credential { User = u, UsersFK = u.UserPK, Username = m.CustomerAccount.Email, Password = "t" }); //-- default password --- !!
//PhoneType pt = dbcontext.PhoneTypes.First(p => p.PhoneType1 == "Business"); // --- phone types --- !!!!
//Phone ph = dbcontext.Phones.Add(new Phone { Phone1 = m.CustomerAccount.Phone, PhoneType = pt });
//CustomerPhoneAssociation cpa = dbcontext.CustomerPhoneAssociations.Add(new CustomerPhoneAssociation { Customer = c, Phone = ph });
//StateCode sc = dbcontext.StateCodes.First(p => p.StateAbbrPK == m.SelectedStateID);
//AddressType at = dbcontext.AddressTypes.First(p => p.AddressType1 == "H"); // --- address types --- !!!
//Address a = dbcontext.Addresses.Add(new Address { Address1 = m.CustomerAccount.Address1, Address2 = m.CustomerAccount.Address2, City = m.CustomerAccount.City, ZipCode = m.CustomerAccount.Zip, StateCode = sc });
//CustomerAddressAssociation caa = dbcontext.CustomerAddressAssociations.Add(new CustomerAddressAssociation { Address = a, Customer = c, AddressType = at });
dbcontext.SaveChanges();
}
catch (Exception ex)
{
Console.WriteLine(ex.TargetSite);
}
return RedirectToAction("Index");
}
示例12: Remove
public ActionResult Remove(EmployeeSetupWithRolesModel m, string command)
{
var dbcontext = new SemplestModel.Semplest();
if (command.ToLower() == "cancel") return RedirectToAction("Index");
if (command.ToLower() == "delete") {
try
{
var user = dbcontext.Users.ToList().Find(p => p.UserPK == m.EmployeeSetup.UserPK);
//need to add effective date to db ---><><>
var employee = dbcontext.Employees.ToList().Find(p => p.UsersFK == m.EmployeeSetup.UserPK);
var userrolesassociation = dbcontext.UserRolesAssociations.ToList().Find(p => p.UsersFK == m.EmployeeSetup.UserPK);
var credential = dbcontext.Credentials.ToList().Find(p => p.UsersFK == m.EmployeeSetup.UserPK);
var employeecustomerassociation = dbcontext.EmployeeCustomerAssociations.ToList().Find(p => p.EmployeeFK.Equals(m.EmployeeSetup.UserPK));
if (employeecustomerassociation != null) throw new Exception("Could not delete employee");
dbcontext.Users.Remove(user);
dbcontext.Employees.Remove(employee);
dbcontext.UserRolesAssociations.Remove(userrolesassociation);
dbcontext.Credentials.Remove(credential);
dbcontext.SaveChanges();
TempData["message"] = "Employee " + m.EmployeeSetup.FirstName + " " + m.EmployeeSetup.LastName + " has been successfully deleted.";
}
catch(Exception ex)
{
TempData["message"] = "Employee " + m.EmployeeSetup.FirstName + " " + m.EmployeeSetup.LastName + " could NOT be deleted.";
}
}
//return View();
return RedirectToAction("Index");
}
示例13: Edit
//.........这里部分代码省略.........
Value = r.EmployeeTypeID.ToString(),
Text = r.EmployeeType1.ToString()
});
return View(m);
}
var user = dbcontext.Users.ToList().Find(p => p.UserPK == m.EmployeeSetup.UserPK);
user.FirstName = m.EmployeeSetup.FirstName;
user.MiddleInitial = m.EmployeeSetup.MiddleInitial;
user.LastName = m.EmployeeSetup.LastName;
user.Email = m.EmployeeSetup.Email;
user.EditedDate = DateTime.Now;
user.IsActive = m.EmployeeSetup.isActive;
UpdateModel(user);
//need to add effective date to db ---><><>
var employee = dbcontext.Employees.ToList().Find(p => p.UsersFK == m.EmployeeSetup.UserPK);
employee.EmployeeTypeFK = m.SelectedEmployeeTypeID;
employee.ReportingTo = m.SelectedReportingToID == -1 ? default(int?) : m.SelectedReportingToID;
employee.HireDate = m.EmployeeSetup.HireDate;
UpdateModel(employee);
var userrolesassociation = dbcontext.UserRolesAssociations.ToList().Find(p => p.UsersFK == m.EmployeeSetup.UserPK);
userrolesassociation.RolesFK = m.SelectedRoleID;
UpdateModel(userrolesassociation);
var credentials = dbcontext.Credentials.ToList().Find(p => p.UsersFK == m.EmployeeSetup.UserPK);
credentials.Username = m.EmployeeSetup.UserID;
credentials.Password = m.EmployeeSetup.UserPassword;
UpdateModel(credentials);
dbcontext.SaveChanges();
////repopulate states ddl
//var states = (from sc in dbcontext.StateCodes select sc).ToList();
//m.States = states.Select(r => new SelectListItem
//{
// Value = r.StateAbbrPK.ToString(),
// Text = r.StateAbbr.ToString()
//});
////repopulate reps ddl
//var allreps = from e in dbcontext.Employees
// join eca in dbcontext.EmployeeCustomerAssociations on e.EmployeePK equals eca.EmployeeFK
// join et in dbcontext.EmployeeTypes on e.EmployeeTypeFK equals et.EmployeeTypeID
// join u in dbcontext.Users on e.UsersFK equals u.UserPK
// where (et.EmployeeType1 == "Rep")
// select new EmployeeCustomerAssociaitionModel
// {
// AccountNumber = eca.CustomerFK,
// employeePK = e.EmployeePK,
// EmployeeType = et.EmployeeType1,
// EmployeeUserPK = u.UserPK,
// FirstName = u.FirstName,
// LastName = u.LastName
// };
//List<EmployeeCustomerAssociaitionModel> ll1 = allreps.ToList();
//List<SelectListItem> sl1 = new List<SelectListItem>();
//foreach (EmployeeCustomerAssociaitionModel s in ll1)
//{
// SelectListItem mylistitem = new SelectListItem();
// mylistitem.Text = s.FirstName + " " + s.LastName;
示例14: SetKeywordsDeleted
public void SetKeywordsDeleted(List<int> keywordIds, int promoId)
{
using (var dbcontext = new SemplestModel.Semplest())
{
foreach (int keywordId in keywordIds)
dbcontext.PromotionKeywordAssociations.Where(key => key.KeywordFK == keywordId).First(key => key.PromotionFK == promoId).IsDeleted = true;
dbcontext.SaveChanges();
}
}
示例15: SaveProductGroupAndCampaign
public void SaveProductGroupAndCampaign(int userid, CampaignSetupModel model)
{
using (var dbcontext = new SemplestModel.Semplest())
{
// get the customerfk from userid
var queryCustFk = from c in dbcontext.Users where c.UserPK == userid select c.CustomerFK;
var i = queryCustFk.FirstOrDefault();
if (i != null)
{
var custfk = (int)i;
// check if the ProductGroupName already exists
var queryProdGrp = from c in dbcontext.ProductGroups
where c.CustomerFK == custfk && c.ProductGroupName == model.ProductGroup.ProductGroupName
select c;
if (queryProdGrp.Any())
{
// product grp already exists so update the product group
var updateProdGrp = queryProdGrp.FirstOrDefault();
if (updateProdGrp != null)
{
updateProdGrp.ProductGroupName = model.ProductGroup.ProductGroupName;
updateProdGrp.StartDate = Convert.ToDateTime(model.ProductGroup.StartDate, new CultureInfo("en-Us"));
updateProdGrp.EndDate = String.IsNullOrEmpty(model.ProductGroup.EndDate) ? (DateTime?)null : Convert.ToDateTime(model.ProductGroup.EndDate);
// get promotion and update it
var updatePromotion = GetPromotionFromProductGroup(updateProdGrp, model.ProductGroup.ProductPromotionName);
// if this is null means promotion name changed so create a new promotion
if (updatePromotion == null)
{
// create new promotion
updatePromotion = CreatePromotionFromModel(model, dbcontext.Configurations.First().CustomerDefaultPerCampaignFlatFeeAmount);
updatePromotion.ProductGroupFK = updateProdGrp.ProductGroupPK;
// add geotargeting to promotion
AddGeoTargetingToPromotion(updatePromotion, model, custfk);
// promotion ads
AddPromotionAdsToPromotion(updatePromotion, model, custfk);
dbcontext.Promotions.Add(updatePromotion);
}
else
{
// update promotion
UpdatePromotionFromModel(updatePromotion, model, dbcontext, custfk);
}
}
dbcontext.SaveChanges();
// we need to set this because the _dbcontext is and campaign is updated so reflect changes we need to create new context
_savedCampaign = true;
}
else
{
// create product group
var prodgroup = new ProductGroup
{
ProductGroupName = model.ProductGroup.ProductGroupName,
IsActive = true,
CustomerFK = custfk,
StartDate = Convert.ToDateTime(model.ProductGroup.StartDate, new CultureInfo("en-Us")),
EndDate = String.IsNullOrEmpty(model.ProductGroup.EndDate) ? (DateTime?)null : Convert.ToDateTime(model.ProductGroup.EndDate)
};
// create promotion
var promo = CreatePromotionFromModel(model, dbcontext.Configurations.First().CustomerDefaultPerCampaignFlatFeeAmount);
// add advertising engines that are selected
SavePromotionAdEngineSelected(promo, model, dbcontext);
// add geotargeting to promotion
AddGeoTargetingToPromotion(promo, model, custfk);
// save site links
AddSiteLinksToPromotion(promo, model, custfk);
// promotion ads
AddPromotionAdsToPromotion(promo, model, custfk);
// add product group
dbcontext.ProductGroups.Add(prodgroup);
// add promotion
dbcontext.Promotions.Add(promo);
dbcontext.SaveChanges();
// save negative keywords
SaveNegativeKeywords(promo, model, dbcontext);
// we need to set this because the _dbcontext is and campaign is updated so reflect changes we need to create new context
_savedCampaign = true;
}
}
}
}