public ActionResult ActivateQuote(string Id) { int nObsoleteId = Convert.ToInt32(Id); tblQuoteLog result = new tblQuoteLog(); SR_Log_DatabaseSQLEntities objdb = new SR_Log_DatabaseSQLEntities(); var quote = (from b in objdb.tblObsolete_Quotes where b.Id == nObsoleteId select b).ToList(); var uid_quotelog = objdb.tblQuoteLogs.OrderByDescending(u => u.UID).FirstOrDefault(); var uid_obsquotelog = objdb.tblObsolete_Quotes.OrderByDescending(u => u.UID).FirstOrDefault(); string bidate = "1/1/1753"; if (quote[0].BidDate != null) { bidate = Convert.ToString(quote[0].BidDate); } result.BidDate = Convert.ToDateTime(bidate); result.BiddingAs = quote[0].BiddingAs; result.BidTo = quote[0].BidTo; result.ProjectName = quote[0].ProjectName; result.Division = quote[0].Division; result.LastAddendumRecvd = quote[0].LastAddendumRecvd; result.Estimator = quote[0].Estimator; result.QuoteNumber = quote[0].QuoteNumber; result.UID = quote[0].UID; result.EngineersEstimate = quote[0].EngineersEstimate; result.Notes = quote[0].Notes; result.JobWalkDate = quote[0].Job_Walk_Date; result.QADeadLineDateTime = quote[0].QADeadLineDateTime; result.QuoteStatus = quote[0].QuoteStatus; result.dtpLastDateFollowup = quote[0].dtpLastDateFollowup; result.LastFollowupBy = quote[0].LastFollowupBy; result.FollowupNote = quote[0].FollowupNote; result.EmailAddress = quote[0].EmailAddress; QuoteLogRepository _repo = new QuoteLogRepository(); _repo.AddActivateQuoteLog(result, "T"); var act = new ActivityRepository(); act.AddActivityLog(Convert.ToString(Session["User"]), "Archived Quote", "Activate Quote ", "Archived Quote " + quote[0].UID.ToString() + " activated by user " + Convert.ToString(Session["User"]) + "."); foreach (var detail in quote) { objdb.tblObsolete_Quotes.Remove(detail); } objdb.SaveChanges(); act.AddActivityLog(Convert.ToString(Session["User"]), "Delete Archived Quote", "Activate Quote ", "Archived Quote " + quote[0].UID.ToString() + " deleted after moving to current by user " + Convert.ToString(Session["User"]) + "."); JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer(); string result1 = javaScriptSerializer.Serialize(result); return(Json(result1, JsonRequestBehavior.AllowGet)); }
public JsonResult SetInActive(Int32 Id, Int32 customerId, bool setdefault) { SR_Log_DatabaseSQLEntities db = new SR_Log_DatabaseSQLEntities(); // if (setdefault == true) // { tblCustomer cust = db.tblCustomers.Where(x => x.CustomerId == customerId).FirstOrDefault(); cust.IsInActive = setdefault; db.SaveChanges(); //} tblCustomer customer = db.tblCustomers.Where(x => x.CustomerId == customerId).FirstOrDefault(); var act = new ActivityRepository(); if (setdefault == true) { act.AddActivityLog(Convert.ToString(Session["User"]), "Update Customer Status", "SetInActive", "Customer " + customer.CustomerName + " status is set as inactive by user " + Convert.ToString(Session["User"]) + "."); } else { act.AddActivityLog(Convert.ToString(Session["User"]), "Update Customer Status", "SetInActive", "Customer " + customer.CustomerName + " status is set as active by user " + Convert.ToString(Session["User"]) + "."); } return(Json(true, JsonRequestBehavior.AllowGet)); }
public ActionResult ArchieveRecord(string Id) { // ObsoleteBidLogViewModel result = new ObsoleteBidLogViewModel(); int nId = Convert.ToInt32(Id); QuoteLogRepository _repo = new QuoteLogRepository(); tblObsolete_Quote result = new tblObsolete_Quote(); SR_Log_DatabaseSQLEntities objdb = new SR_Log_DatabaseSQLEntities(); var quote = (from b in objdb.tblQuoteLogs where b.Id == nId select b).ToList(); string UID = quote[0].UID.ToString(); string bidate = "1/1/1753"; if (quote[0].BidDate != null) { bidate = Convert.ToString(quote[0].BidDate); } result.BidDate = Convert.ToDateTime(bidate); result.BiddingAs = quote[0].BiddingAs; result.BidTo = quote[0].BidTo; result.ProjectName = quote[0].ProjectName; result.Estimator = quote[0].Estimator; result.QuoteNumber = quote[0].QuoteNumber; result.Notes = quote[0].Notes; result.EngineersEstimate = quote[0].EngineersEstimate; result.Division = quote[0].Division; result.UID = quote[0].UID; result.RedSheet = quote[0].RedSheet; result.ScopeLetter = quote[0].ScopeLetter; result.Job_Walk_Date = quote[0].JobWalkDate; result.QADeadLineDateTime = quote[0].QADeadLineDateTime; result.Mandatory_Job_Walk = (quote[0].MandetoryJobWalk == null ? false : true); result.LastAddendumRecvd = quote[0].LastAddendumRecvd; result.QuoteStatus = quote[0].QuoteStatus; result.dtpLastDateFollowup = quote[0].dtpLastDateFollowup; result.LastFollowupBy = quote[0].LastFollowupBy; result.FollowupNote = quote[0].FollowupNote; result.EmailAddress = quote[0].EmailAddress; _repo.AddArchiveQuoteLog(result, "F"); var act = new ActivityRepository(); act.AddActivityLog(Convert.ToString(Session["User"]), "Archive Quote", "ArchieveRecord", "Quote " + quote[0].UID + " archived by user " + Convert.ToString(Session["User"]) + "."); foreach (var detail in quote) { objdb.tblQuoteLogs.Remove(detail); } objdb.SaveChanges(); act.AddActivityLog(Convert.ToString(Session["User"]), "Delete Quote", "ArchieveRecord ", " Quote " + UID + " deleted after archiving by user " + Convert.ToString(Session["User"]) + "."); JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer(); string result1 = javaScriptSerializer.Serialize(result); return(Json(result1, JsonRequestBehavior.AllowGet)); }
public ActionResult UpdateCustomerAddress(CustomerAddressViewModel custaddress) { SR_Log_DatabaseSQLEntities db = new SR_Log_DatabaseSQLEntities(); if (custaddress.CustomerId != 0) { CustomerRepository objdata = new CustomerRepository(); if (string.IsNullOrEmpty(custaddress.Address1) == false) { custaddress.Address1 = custaddress.Address1.ToUpper(); } if (string.IsNullOrEmpty(custaddress.Address2) == false) { custaddress.Address2 = custaddress.Address2.ToUpper(); } if (string.IsNullOrEmpty(custaddress.City) == false) { custaddress.City = custaddress.City.ToUpper(); } if (string.IsNullOrEmpty(custaddress.Country) == false) { custaddress.Country = custaddress.Country.ToUpper(); } if (string.IsNullOrEmpty(custaddress.State) == false) { custaddress.State = custaddress.State.ToUpper(); } if (string.IsNullOrEmpty(custaddress.ZipCode) == false) { custaddress.ZipCode = custaddress.ZipCode.ToUpper(); } if (string.IsNullOrEmpty(custaddress.SiteName) == false) { custaddress.SiteName = custaddress.SiteName.ToUpper(); } objdata.AddUpdateCustomerAddress(custaddress, "Update"); tblCustomer customer = db.tblCustomers.Where(x => x.CustomerId == custaddress.CustomerId).FirstOrDefault(); var act = new ActivityRepository(); act.AddActivityLog(Convert.ToString(Session["User"]), "Edit address", "UpdateCustomerAddress", "Addresses for customer " + customer.CustomerName.ToUpper() + " edited by " + Convert.ToString(Session["User"]) + "."); } //CustomerRepository _repository = new CustomerRepository(); //var cust = _repository.GetCustomerDetails(custaddress.CustomerId); tblCustAddress cust = new tblCustAddress(); return(Json(cust, JsonRequestBehavior.AllowGet)); }
public JsonResult SetPrimaryContact(Int32 Id, Int32 customerId, bool setdefault) { SR_Log_DatabaseSQLEntities db = new SR_Log_DatabaseSQLEntities(); if (setdefault == true) { var cust = (from c in db.tblCustContacts where c.CustomerId == customerId && c.Id != Id select c).ToList(); foreach (var c in cust) { tblCustContact contact = db.tblCustContacts.Where(x => x.Id == c.Id).FirstOrDefault(); contact.IsPrimaryContact = false; db.SaveChanges(); } } tblCustContact custcontact = db.tblCustContacts.Where(x => x.Id == Id).FirstOrDefault(); custcontact.IsPrimaryContact = setdefault; db.SaveChanges(); tblCustomer customer = db.tblCustomers.Where(x => x.CustomerId == customerId).FirstOrDefault(); var act = new ActivityRepository(); if (setdefault == true) { act.AddActivityLog(Convert.ToString(Session["User"]), "Update default contact", "SetPrimaryContact", "Default contact set to " + custcontact.CustomerContact + " for customer " + customer.CustomerName + " by user " + Convert.ToString(Session["User"]) + "."); } else { act.AddActivityLog(Convert.ToString(Session["User"]), "Update default contact", "SetPrimaryContact", "Default contact " + custcontact.CustomerContact + " removed for customer " + customer.CustomerName + " by user " + Convert.ToString(Session["User"]) + "."); } return(Json(true, JsonRequestBehavior.AllowGet)); }
public JsonResult DeleteCustomerContact(Int32 Id) { SR_Log_DatabaseSQLEntities db = new SR_Log_DatabaseSQLEntities(); tblCustContact custcontact = db.tblCustContacts.Where(x => x.Id == Id).FirstOrDefault(); int CustomerId = custcontact.CustomerId; string contact = custcontact.CustomerContact; db.tblCustContacts.Remove(custcontact); db.SaveChanges(); tblCustomer customer = db.tblCustomers.Where(x => x.CustomerId == CustomerId).FirstOrDefault(); var act = new ActivityRepository(); act.AddActivityLog(Convert.ToString(Session["User"]), "Delete contact", "DeleteCustomerContact", "Contact " + contact + " of customer " + customer.CustomerName + " deleted by user " + Convert.ToString(Session["User"]) + "."); return(Json(true, JsonRequestBehavior.AllowGet)); }
public JsonResult DeleteCustomerAddress(Int32 Id) { SR_Log_DatabaseSQLEntities db = new SR_Log_DatabaseSQLEntities(); tblCustAddress custaddress = db.tblCustAddresses.Where(x => x.Id == Id).FirstOrDefault(); int customerId = custaddress.CustomerId; db.tblCustAddresses.Remove(custaddress); db.SaveChanges(); tblCustomer customer = db.tblCustomers.Where(x => x.CustomerId == customerId).FirstOrDefault(); var act = new ActivityRepository(); act.AddActivityLog(Convert.ToString(Session["User"]), "Delete address", "DeleteCustomerAddress", "Address " + custaddress.Address1 + " of customer " + customer.CustomerName + " deleted by user " + Convert.ToString(Session["User"]) + "."); return(Json(true, JsonRequestBehavior.AllowGet)); }
public ActionResult UpdateCustomerContact(CustomerContactViewModel custconact) { SR_Log_DatabaseSQLEntities db = new SR_Log_DatabaseSQLEntities(); if (custconact.CustomerId != 0) { CustomerRepository objdata = new CustomerRepository(); if (string.IsNullOrEmpty(custconact.ContactEmail) == false) { custconact.ContactEmail = custconact.ContactEmail.ToUpper(); } if (string.IsNullOrEmpty(custconact.ContactPhone) == false) { custconact.ContactPhone = custconact.ContactPhone.ToUpper(); } if (string.IsNullOrEmpty(custconact.CustomerContact) == false) { custconact.CustomerContact = custconact.CustomerContact.ToUpper(); } objdata.AddUpdateCustomerContact(custconact, "Update"); tblCustomer customer = db.tblCustomers.Where(x => x.CustomerId == custconact.CustomerId).FirstOrDefault(); var act = new ActivityRepository(); act.AddActivityLog(Convert.ToString(Session["User"]), "Edit Contact", "UpdateCustomerContact", "Contacts for customer " + customer.CustomerName.ToUpper() + " edited by " + Convert.ToString(Session["User"]) + "."); //Call SaveActivityLog("frmAddCustomer", "Edit Contact", "Contacts for customer " & UCase(txtCustomerName.Text) & " edited by " & UserInfo.UserName) } //CustomerRepository _repository = new CustomerRepository(); //var cust = _repository.GetCustomerDetails(custconact.CustomerId); tblCustContact cust = new tblCustContact(); return(Json(cust, JsonRequestBehavior.AllowGet)); }
public ActionResult Login(LoginViewModel model) { try { if (ModelState.IsValid) { // EventLog.LogData(DateTime.Now.ToString("dd-MMM-yyyy HH:mm:ss") + " Login - Validating user.", true); var user = new LoginRepository(); var act = new ActivityRepository(); LoginViewModel l = user.GetUserById(model.LoginName, model.Password); if (l == null) { ViewBag.Message = "User Name or Password is incorrect"; ModelState.AddModelError("", "User Name or Password is incorrect"); return(View(model)); } else { // EventLog.LogData(DateTime.Now.ToString("dd-MMM-yyyy HH:mm:ss") + " Login - User Validation completed.", true); //Store user details and previleges in userinfo object Session["User"] = l.LoginName; ViewBag.UserName = l.LoginName; Session["UserInfo"] = l.UserInfo; Session["UserId"] = l.UserInfo.UserId; Session["Admin_Rights"] = l.UserInfo.Admin_Rights; Session["Bid_Log_ReadOnly"] = l.UserInfo.Bid_Log_ReadOnly; Session["SR_Log_ReadOnly"] = l.UserInfo.SR_Log_ReadOnly; Session["Accounting_Rights"] = l.UserInfo.Accounting_Rights; Session["DatabaseUpdate_Rights"] = l.UserInfo.DatabaseUpdate_Rights; if (Session["Bid_Log_ReadOnly"].ToString() == "True" && Session["SR_Log_ReadOnly"].ToString() == "False") { Session["UserRights"] = "Rights: SR Log Table Change, Bid Log Table Read Only"; } if (Session["Bid_Log_ReadOnly"].ToString() == "False" && Session["SR_Log_ReadOnly"].ToString() == "True") { Session["UserRights"] = "Rights: SR Log Table Read Only, Bid Log Table Change"; } if (Session["Bid_Log_ReadOnly"].ToString() == "True" && Session["SR_Log_ReadOnly"].ToString() == "True") { Session["UserRights"] = "Rights: SR Log Table Read Only, Bid Log Table Read Only"; } if (Session["Bid_Log_ReadOnly"].ToString() == "False" && Session["SR_Log_ReadOnly"].ToString() == "False") { Session["UserRights"] = "Rights: SR Log Table Change, Bid Log Table Change"; } TestSiteRepository _repository = new TestSiteRepository(); Session["IsTestSite"] = _repository.GetTestSiteDetails(); //Log activity in database act.AddActivityLog(l.UserInfo.User_Name, "Login", "Login", "User " + l.UserInfo.User_Name + " Logged in."); //Check if ini file settings exist for this user. Else make an entry in database CheckINIFile(l.UserInfo.UserId); return(RedirectToAction("Index", "Home")); } } return(View(model)); //return RedirectToAction("Index", "Home"); } catch (Exception ex) { //SetLoginViewMdelForError(model); ModelState.AddModelError("", ex.Message); return(View(model)); } }
public ActionResult Create(QuoteLogViewModel model, FormCollection form) { QuoteLogRepository _repo = new QuoteLogRepository(); SRLogRepository objdata = new SRLogRepository(); ModelState.Remove("Id"); if (ModelState.IsValid) { SR_Log_DatabaseSQLEntities objdb1 = new SR_Log_DatabaseSQLEntities(); string hdnCustomer = ""; if (string.IsNullOrEmpty(form["hdnCustomer"]) == false) { hdnCustomer = Convert.ToString(form["hdnCustomer"]).ToUpper(); } else { hdnCustomer = Convert.ToString(form["hdnCustomer"]); } string hdnCustUpdate = Convert.ToString(form["hdnCustUpdate"]); if (!string.IsNullOrEmpty(hdnCustUpdate)) { //Add or Update Customer tblCustomer cu = (from cust in objdb1.tblCustomers where cust.CustomerName == hdnCustomer select cust).FirstOrDefault(); CommonFunctions c = new CommonFunctions(); if (cu == null) { tblCustomer custad = new tblCustomer(); custad.CustomerName = hdnCustomer; custad.DateAdded = c.GetCurrentDate(); custad.IsInActive = false; custad.Notes = null; objdb1.tblCustomers.Add(custad); objdb1.SaveChanges(); } } model.BidTo = ""; if (string.IsNullOrEmpty(form["hdnCustomer"]) == false) { model.BidTo = Convert.ToString(form["hdnCustomer"]).ToUpper(); } else { model.BidTo = Convert.ToString(form["hdnCustomer"]); } string strBidAs = ""; if (model.BiddingAsIandC == true) { strBidAs = "0#"; } if (model.BiddingAsElectircal == true) { strBidAs = strBidAs + "1#"; } if (model.BiddingAsPrime == true) { strBidAs = strBidAs + "2#"; } if (model.BiddingAsUnKnown == true) { strBidAs = strBidAs + "3#"; } if (model.BiddingAsNotBidding == true) { strBidAs = strBidAs + "4#"; } if (model.BiddingAsNotQualified == true) { strBidAs = strBidAs + "5#"; } if (model.BiddingAsMechanical == true) { strBidAs = strBidAs + "6#"; } model.BiddingAs = strBidAs; if (model.DivisionConcord == true) { model.Division = "Concord"; } else if (model.DivisionHanford == true) { model.Division = "Hanford"; } else if (model.DivisionSacramento == true) { model.Division = "Sacramento"; } if (string.IsNullOrEmpty(model.ProjectName) == false) { model.ProjectName = model.ProjectName.ToUpper(); } if (string.IsNullOrEmpty(model.QuoteStatus) == false) { model.QuoteStatus = model.QuoteStatus.ToUpper(); } if (string.IsNullOrEmpty(model.LastFollowupBy) == false) { model.LastFollowupBy = model.LastFollowupBy.ToUpper(); } if (string.IsNullOrEmpty(model.FollowupNote) == false) { model.FollowupNote = model.FollowupNote.ToUpper(); } if (string.IsNullOrEmpty(model.EngineersEstimate) == false) { model.EngineersEstimate = model.EngineersEstimate.ToUpper(); } if (string.IsNullOrEmpty(model.Notes) == false) { model.Notes = model.Notes.ToUpper(); } _repo.UpdateQuoteLog(model); ViewBag.UId = model.UID; ViewBag.ID = model.Id; string dtpLastDateFollowup = ""; if (model.dtpLastDateFollowup == null) { dtpLastDateFollowup = ""; } else { dtpLastDateFollowup = Convert.ToDateTime(model.dtpLastDateFollowup).ToString("MM-dd-yyyy"); } string bidDate = ""; if (model.BidDate == null) { bidDate = ""; } else { bidDate = Convert.ToDateTime(model.BidDate).ToString("MM-dd-yyyy"); } SendQuoteModifyMailSMTP(dtpLastDateFollowup, model.Email, model.BidTo, model.ProjectName, bidDate, model.QuoteStatus, model.LastFollowupBy, model.FollowupNote); var act = new ActivityRepository(); act.AddActivityLog(Convert.ToString(Session["User"]), "Update Quote", "Create", "Quote " + model.UID + " updated by user " + Convert.ToString(Session["User"]) + "."); ViewBag.Message = "Record Updated Successfully And Quote Modified Status Mail Sent Succesfully"; } //BidLogViewModel objcre = new BidLogViewModel(); objdata = new SRLogRepository(); model.CustomerList = objdata.GetCustomer(); model.GroupUsersList = objdata.GetGroupUser(); bool bExistEstimator = false; foreach (var i in model.GroupUsersList) { if (i.UserName == model.Estimator) { bExistEstimator = true; } } if (bExistEstimator == false) { tblGroupUser g = new tblGroupUser(); g.UserName = model.Estimator; g.Userid = model.Estimator; g.Group_Name = ""; model.GroupUsersList.Add(g); } ViewBag.UpdateDisable = false; if (Convert.ToString(Session["SR_Log_ReadOnly"]) == "True" && Convert.ToString(Session["Bid_Log_ReadOnly"]) == "True") { ViewBag.UpdateDisable = true; } model.emailids = _repo.GetEmailInfo(); return(View("Create", model)); }
public void SaveMailInfo(string[] bonding, string[] bidresult, string[] customerinfo, string User) { SR_Log_DatabaseSQLEntities db = new SR_Log_DatabaseSQLEntities(); List <Bonding_Mail_TO> allEmails = (from p in db.Bonding_Mail_TO select p).ToList(); foreach (Bonding_Mail_TO t in allEmails) { db.Bonding_Mail_TO.Remove(t); db.SaveChanges(); } var act = new ActivityRepository(); act.AddActivityLog(User, "ManageMailList", "SaveMailInfo", "All existing bonding mails deleted by " + User); //Call SaveActivityLog("Frm_Bonding_prevailing_Email", "Delete all bonding mails", "All existing bonding mails deleted by " & UserInfo.UserName) for (int i = 0; i < bonding.Length; i++) { if (bonding[i].ToString().Trim() != "") { Bonding_Mail_TO objbonding = new Bonding_Mail_TO(); objbonding.BondingMailTO = bonding[i].ToString(); db.Bonding_Mail_TO.Add(objbonding); db.SaveChanges(); act.AddActivityLog(User, "ManageMailList", "SaveMailInfo", "Bonding mail " + bonding[i].ToString() + " added in bonding mails by " + User); } //Call SaveActivityLog("Frm_Bonding_prevailing_Email", "Insert bonding mail", "Bonding mail " & lstTo.List(j) & " added in bonding mails by " & UserInfo.UserName) } List <Customer_Info_Mail> allEmailsofcustomer = (from p in db.Customer_Info_Mail select p).ToList(); foreach (Customer_Info_Mail t in allEmailsofcustomer) { db.Customer_Info_Mail.Remove(t); db.SaveChanges(); } act.AddActivityLog(User, "ManageMailList", "SaveMailInfo", "All existing customer info mails deleted by " + User); //Call SaveActivityLog("Frm_Bonding_prevailing_Email", "Delete all customer info mails", "All existing customer info mails deleted by " & UserInfo.UserName) for (int i = 0; i < customerinfo.Length; i++) { if (customerinfo[i].ToString().Trim() != "") { Customer_Info_Mail objcustomer = new Customer_Info_Mail(); objcustomer.CustomerInfoMail = customerinfo[i].ToString(); db.Customer_Info_Mail.Add(objcustomer); db.SaveChanges(); act.AddActivityLog(User, "ManageMailList", "SaveMailInfo", "Customer info mail " + customerinfo[i].ToString() + " added in customer info mails by " + User); //Call SaveActivityLog("Frm_Bonding_prevailing_Email", "Insert customer info mail", "Customer info mail " & lstCustTo.List(j) & " added in customer info mails by " & UserInfo.UserName) } } List <Bidlog_Result_Mail> allEmailsbidresult = (from p in db.Bidlog_Result_Mail select p).ToList(); foreach (Bidlog_Result_Mail t in allEmailsbidresult) { db.Bidlog_Result_Mail.Remove(t); db.SaveChanges(); } act.AddActivityLog(User, "ManageMailList", "SaveMailInfo", "All existing bidlog result mails deleted by " + User); //Call SaveActivityLog("Frm_Bonding_prevailing_Email", "Delete all bidlog result mails", "All existing bidlog result mails deleted by " & UserInfo.UserName) for (int i = 0; i < bidresult.Length; i++) { if (bidresult[i].ToString().Trim() != "") { Bidlog_Result_Mail objbidresult = new Bidlog_Result_Mail(); objbidresult.BidlogResultMail = bidresult[i].ToString(); db.Bidlog_Result_Mail.Add(objbidresult); db.SaveChanges(); act.AddActivityLog(User, "ManageMailList", "SaveMailInfo", "Bidlog mail " + bidresult[i].ToString() + " added in bidlog results mails by " + User); //Call SaveActivityLog("Frm_Bonding_prevailing_Email", "Insert bidlog result mail", "Bidlog mail " & lstBidTo.List(j) & " added in bidlog results mails by " & UserInfo.UserName) } } }
public ActionResult Save(CustomerViewModel cust) { ModelState.Remove("CustomerId"); int CustomerId = 0; CustomerId = cust.CustomerId; if (ModelState.IsValid) { // string jobsite = Convert.ToString(form["hdnJobSiteAddress"]); string Customer = cust.CustomerName.ToUpper(); cust.CustomerName = cust.CustomerName.ToUpper(); if (string.IsNullOrEmpty(cust.Notes) == false) { cust.Notes = cust.Notes.ToUpper(); } SR_Log_DatabaseSQLEntities db = new SR_Log_DatabaseSQLEntities(); if (cust.CustomerId != 0) { var editcust = db.tblCustomers.Where(x => x.CustomerName.Trim().ToUpper() == Customer.Trim().ToUpper() && x.CustomerId != cust.CustomerId).FirstOrDefault(); if (editcust != null) { cust.CustomerId = cust.CustomerId; ViewBag.CustomerId = cust.CustomerId; ViewBag.Message = "This Customer already present. Please add different name And Try Again."; ViewBag.Adddisable = true; ViewBag.Deletedisable = true; var customerexist = _repository.GetCustomerDetails(Convert.ToInt32(CustomerId)); cust.lstCustAddress = customerexist.lstCustAddress; cust.lstCustContact = customerexist.lstCustContact; return(View("Index", cust)); } } else { var existcust = db.tblCustomers.Where(x => x.CustomerName.Trim().ToUpper() == Customer.Trim().ToUpper()).FirstOrDefault(); if (existcust != null) { cust.CustomerId = cust.CustomerId; ViewBag.CustomerId = cust.CustomerId; ViewBag.Message = "This Customer already present. Please add different name And Try Again."; ViewBag.Adddisable = true; ViewBag.Deletedisable = true; var customerexist2 = _repository.GetCustomerDetails(Convert.ToInt32(CustomerId)); cust.lstCustAddress = customerexist2.lstCustAddress; cust.lstCustContact = customerexist2.lstCustContact; return(View("Index", cust)); } } CustomerRepository objdata = new CustomerRepository(); // CustomerId = objdata.AddUpdateCustomer(cust, "Add"); CustomerId = objdata.AddUpdateCustomer(cust); // Call SaveActivityLog("frmAddCustomer", "Add Customer", "Customer " + UCase(txtCustomerName.Text) + " added by user " & UserInfo.UserName & ".") var act = new ActivityRepository(); act.AddActivityLog(Convert.ToString(Session["User"]), "Add Customer", "Save", "Customer " + cust.CustomerName.ToUpper() + " added by user " + Convert.ToString(Session["User"]) + "."); if (cust.CustomerId == 0) { SendCustomerMailSMTP(Convert.ToInt32(CustomerId), cust.CustomerName); } cust.CustomerId = CustomerId; ViewBag.CustomerId = CustomerId; ViewBag.Adddisable = false; ViewBag.Deletedisable = false; ViewBag.Message = "Customer details saved successfully."; } else { ViewBag.Adddisable = true; } var customer = _repository.GetCustomerDetails(Convert.ToInt32(CustomerId)); return(View("Index", customer)); }
public ActionResult ImportCustomerContacts(HttpPostedFileBase postedFile) { try { string filePath = string.Empty; if (postedFile != null) { string path = Server.MapPath("~/ImportCustomerContacts/"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } filePath = path + Path.GetFileName(postedFile.FileName); string extension = Path.GetExtension(postedFile.FileName); postedFile.SaveAs(filePath); DataTable dtToExport = new DataTable(); int cnt = 0; using (StreamReader sr = new StreamReader(filePath)) { while (!sr.EndOfStream) { //string[] col = sr.ReadLine().Split(','); string[] col = Regex.Split(sr.ReadLine(), ",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)"); DataRow dr = dtToExport.NewRow(); if (col.Length > 0) { for (int i = 0; i < col.Length; i++) { if (cnt == 0) { DataColumn dc = new DataColumn(); dc.ColumnName = col[i].ToString(); dtToExport.Columns.Add(dc); } else { dr[i] = col[i].ToString(); } } if (cnt > 0) { dtToExport.Rows.Add(dr); } if (cnt == 0) { cnt++; } } } } string[] columnNames = dtToExport.Columns.Cast <DataColumn>().Select(x => x.ColumnName).ToArray(); if (columnNames[0] != "Customer Name" && columnNames[1] != "Customer Contact" && columnNames[2] != "Contact Phone" && columnNames[3] != "Contact Email") { ViewBag.Message = "CSV file not in correct format. Please select valid CSV file and try again!"; return(View("ManageCustomerContacts")); } CustomerRepository _respository = new CustomerRepository(); for (int i = 0; i < dtToExport.Rows.Count; i++) { CustomerViewModel cst = new CustomerViewModel(); cst.CustomerName = dtToExport.Rows[i][0].ToString().Replace(@"""", ""); cst.InActive = false; cst.Notes = ""; int CustomerId; CustomerId = _respository.AddUpdateCustomerImport(cst); // Call SaveActivityLog("frmImportCustomers", "Import Customer", "Customer " + cst.CustomerName + " added from csv file " + postedFile.FileName + " by user " + Convert.ToString(Session["User"]) + ".") var act = new ActivityRepository(); act.AddActivityLog(Convert.ToString(Session["User"]), "Import Customer", "ImportCustomerContacts", "Customer " + cst.CustomerName + " added from csv file " + postedFile.FileName + " by user " + Convert.ToString(Session["User"]) + "."); if (dtToExport.Rows[i][1].ToString() != "" && dtToExport.Rows[i][2].ToString() != " && dtToExport.Rows[i][3].ToString() != ") { CustomerContactViewModel cstAdd = new CustomerContactViewModel(); cstAdd.CustomerId = CustomerId; cstAdd.CustomerContact = dtToExport.Rows[i][1].ToString(); cstAdd.ContactPhone = dtToExport.Rows[i][2].ToString(); cstAdd.ContactEmail = dtToExport.Rows[i][3].ToString(); cstAdd.IsPrimaryContact = false; // cstAdd.DateAdded = System.DateTime.Now; CommonFunctions c = new CommonFunctions(); cstAdd.DateAdded = c.GetCurrentDate(); _respository.AddUpdateCustomerContact(cstAdd, "Add"); act = new ActivityRepository(); act.AddActivityLog(Convert.ToString(Session["User"]), "Import Customer Contacts", "ImportCustomer", "Contacts added for customer " + cst.CustomerName + " from csv file " + postedFile.FileName + " by user " + Convert.ToString(Session["User"]) + "."); } } } else { ViewBag.Message = "Please select file to import"; } return(View("ManageCustomerContacts")); } catch (Exception ex) { ViewBag.Message = "CSV file not in correct format. Please select valid CSV file and try again!"; return(View("ManageCustomerContacts")); } }