public async Task <ActionResult> Create([Bind(Include = "Id,FirstName,LastName,Phone,Email,CreditCard,CreditCardType,CardExpMo,CardExpYr,UserID,CreatedDate,UpdatedDate,Sort,Description,Notes,UserName,Password,ConfirmPassword")] Customer customer) { var _controller = new AccountController(); if (ModelState.IsValid) { customer.CreatedDate = DateTime.Now; customer.UpdatedDate = DateTime.Now; customer.Sort = 33; db.Customers.Add(customer); var user = new ApplicationUser() { UserName = customer.UserName, CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now }; IdentityResult result = await _controller.UserManager.CreateAsync(user, customer.Password); if (result.Succeeded) { customer.UserID = user.Id; db.SaveChanges(); _controller.UserManager.AddToRole(user.Id, "Customer"); string email = customer.Email; string username = customer.UserName; string adminemail = ConfigurationManager.AppSettings["adminemail"].ToString(); string admintemple = ConfigurationManager.AppSettings["admintempleforcustomer"].ToString(); string subject = ConfigurationManager.AppSettings["subject"].ToString(); string AdminUserName = ConfigurationManager.AppSettings["adminusername"].ToString(); var sendemail = new EmailService.Service.EmailService(); sendemail.SendEmail(email, "addcustomer.html", "verfication", username); sendemail.SendEmail(adminemail, admintemple, subject, AdminUserName); this.AddNotification("Customer Created successfully.", NotificationType.SUCCESS); #region Saveinemailrecord var emailrecord = new emailrecord(); emailrecord.Email_Sender = "*****@*****.**"; emailrecord.Email_Receiver = email; emailrecord.Send_Date = DateTime.Now.ToString(); emailrecord.Subject = subject; emailrecord.Message = "New Customer Added "; db.EmailRecord.Add(emailrecord); db.SaveChanges(); #endregion return(RedirectToAction("Index")); } else { AddErrors(result); } } return(View(customer)); }
public HttpResponseMessage contactus(ContactViewModel contact) { try { if (ModelState.IsValid) { string CustomerName = contact.Name; string CustomerMessage = contact.Message; string CustomerEmail = contact.EmailAddress; string adminemail = ConfigurationManager.AppSettings["adminemail"].ToString(); string admintemple = ConfigurationManager.AppSettings["admintemple"].ToString(); string subject = ConfigurationManager.AppSettings["subject"].ToString(); string Thankyou = ConfigurationManager.AppSettings["Thankyou"].ToString(); string CustomerContactus = ConfigurationManager.AppSettings["CustomerContactus"].ToString(); string AdminUserName = ConfigurationManager.AppSettings["adminusername"].ToString(); var sendemail = new EmailService.Service.EmailService(); //for cutomer sendemail.SendEmail(CustomerEmail, Thankyou, "Thank you For Contant us", CustomerName); //for Admin sendemail.SendEmail(adminemail, CustomerContactus, subject, CustomerEmail + " Message: " + CustomerMessage); var result = new { success = true, }; return(Request.CreateResponse(HttpStatusCode.OK, result)); } } catch (Exception ex) { var result = new { error = ex.InnerException.Message.ToString(), success = false }; return(Request.CreateResponse(HttpStatusCode.OK, result)); } return(Request.CreateResponse(HttpStatusCode.OK)); }
public async Task <ActionResult> Create([Bind(Include = "Id,CompanyName,FirstName,LastName,Title,Address1,Address2,City,State,PostalCode,Country,Phone,Email,URL,Logo,SupplierType,UserID,PlanID,UserName,Password")] Supplier supplier, HttpPostedFileBase file) { var _controller = new AccountController(); if (!string.IsNullOrEmpty(supplier.UserName)) { var _user = _controller.UserManager.FindByNameAsync(supplier.UserName); if (_user.Result != null) { ModelState.AddModelError("Already Exist", "User already exist please provide different user name"); } } if (ModelState.IsValid) { var _plan = db.Plans.Where(x => x.Id == supplier.PlanID).FirstOrDefault(); supplier.CreatedDate = DateTime.Now; supplier.UpdatedDate = DateTime.Now; supplier.Sort = 33; supplier.ParentSupplierID = 0; supplier.ProductCount = _plan.ProductBucketCount; supplier.PlanStartDate = DateTime.Now; supplier.PlanEndDate = DateTime.Now.AddDays(_plan.PlanFrequency == "1" ? 30 : 365); supplier.UserCount = _plan.UserBucketCount; if (file != null) { string pic = System.IO.Path.GetFileName(file.FileName); string path = System.IO.Path.Combine( Server.MapPath("~/SupplierImage"), pic); // file is uploaded file.SaveAs(path); supplier.Logo = pic; // save the image path path to the database or you can send image // directly to database // in-case if you want to store byte[] ie. for DB using (MemoryStream ms = new MemoryStream()) { file.InputStream.CopyTo(ms); byte[] array = ms.GetBuffer(); } } db.Suppliers.Add(supplier); var user = new ApplicationUser() { UserName = supplier.UserName, CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now }; IdentityResult result = await _controller.UserManager.CreateAsync(user, supplier.Password); if (result.Succeeded) { supplier.UserID = user.Id; db.SaveChanges(); _controller.UserManager.AddToRole(user.Id, "Supplier"); //Add Claims to the AspNetUserClaims table for the supplier registerd. var Claims = db.Claims.Where(x => x.Role == "Supplier").ToList(); var _connectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString.ToString(); using (SqlConnection connection = new SqlConnection(_connectionString)) { connection.Open(); foreach (var claim in Claims) { String query = "INSERT INTO [dbo].[AspNetUserClaims]([ClaimType],[ClaimValue],[UserId],[ClaimID],[IsActive],[DisplayLabel],[Discriminator],[User_Id]) VALUES(@ClaimType,@ClaimValue,@UserId,@ClaimID,@IsActive,@DisplayLabel,@Discriminator,@User_Id)"; using (SqlCommand command = new SqlCommand(query, connection)) { command.Parameters.AddWithValue("@ClaimType", claim.ClaimType); command.Parameters.AddWithValue("@ClaimValue", claim.ClaimValue); command.Parameters.AddWithValue("@UserId", user.Id); command.Parameters.AddWithValue("@ClaimID", claim.Id); command.Parameters.AddWithValue("@IsActive", "True"); command.Parameters.AddWithValue("@DisplayLabel", "abc"); command.Parameters.AddWithValue("@Discriminator", "ApplicationUserClaim"); command.Parameters.AddWithValue("@User_Id", user.Id); int _result = command.ExecuteNonQuery(); // Check Error if (_result < 0) { Console.WriteLine("Error inserting data into Database!"); } } } connection.Close(); } //foreach (var claim in Claims) //{ // ApplicationUserClaim UserClaim = new ApplicationUserClaim(); // //_controller.UserManager.AddClaim(user.Id, new Claim(claim.ClaimType, claim.ClaimValue)); // UserClaim.ClaimType = claim.ClaimType; // UserClaim.ClaimValue = claim.ClaimValue; // UserClaim.User = db.Users.FirstOrDefault(x => x.Id == user.Id); // UserClaim.IsActive = true; // UserClaim.User_Id = user.Id; // db.AspNetUserClaims.Add(UserClaim); //} //db.SaveChanges(); //Send confirmation mail to user and admin string email = supplier.Email; string username = supplier.UserName; string adminemail = ConfigurationManager.AppSettings["adminemail"].ToString(); string admintemple = ConfigurationManager.AppSettings["admintemple"].ToString(); string subject = ConfigurationManager.AppSettings["subject"].ToString(); string AdminUserName = ConfigurationManager.AppSettings["adminusername"].ToString(); var sendemail = new EmailService.Service.EmailService(); sendemail.SendEmail(email, "ForAdmin.html", "verfication", username); sendemail.SendEmail(adminemail, admintemple, subject, AdminUserName); this.AddNotification("Created successfully.", NotificationType.SUCCESS); return(RedirectToAction("Index")); } else { AddErrors(result); } } ViewBag.PlanID = new SelectList(db.Plans, "Id", "PlanName", supplier.PlanID); var allplans = db.Plans.ToList(); ViewBag.allplans = allplans; return(View(supplier)); }
public async Task <ActionResult> CreateNew([Bind(Include = "Id,Name,Email,UserName,Password,Address,PlanID")] SupplierVM supplier) { try { if (ModelState.IsValid) { var _controller = new AccountController(); var _plan = db.Plans.Where(x => x.Id == supplier.PlanID).FirstOrDefault(); var _supplier = new Supplier(); _supplier.CreatedDate = DateTime.Now; _supplier.UpdatedDate = DateTime.Now; _supplier.Sort = 33; _supplier.ParentSupplierID = 0; _supplier.ProductCount = _plan.ProductBucketCount; _supplier.PlanStartDate = DateTime.Now; _supplier.PlanEndDate = DateTime.Now.AddDays(_plan.PlanFrequency == "1" ? 30 : 365); _supplier.UserCount = _plan.UserBucketCount; _supplier.FirstName = supplier.Name; _supplier.Email = supplier.Email; _supplier.Address1 = supplier.Address; _supplier.UserName = supplier.UserName; _supplier.LastName = ""; _supplier.PlanID = supplier.PlanID; _supplier.Password = supplier.Password; db.Suppliers.Add(_supplier); var user = new ApplicationUser() { UserName = supplier.UserName, CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now }; IdentityResult result = await _controller.UserManager.CreateAsync(user, supplier.Password); if (result.Succeeded) { _supplier.UserID = user.Id; db.SaveChanges(); _controller.UserManager.AddToRole(user.Id, "Supplier"); //Add Claims to the AspNetUserClaims table for the supplier registerd. var Claims = db.Claims.Where(x => x.Role == "Supplier").ToList(); var _connectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString.ToString(); using (SqlConnection connection = new SqlConnection(_connectionString)) { connection.Open(); foreach (var claim in Claims) { String query = "INSERT INTO [dbo].[AspNetUserClaims]([ClaimType],[ClaimValue],[UserId],[ClaimID],[IsActive],[DisplayLabel],[Discriminator],[User_Id]) VALUES(@ClaimType,@ClaimValue,@UserId,@ClaimID,@IsActive,@DisplayLabel,@Discriminator,@User_Id)"; using (SqlCommand command = new SqlCommand(query, connection)) { command.Parameters.AddWithValue("@ClaimType", claim.ClaimType); command.Parameters.AddWithValue("@ClaimValue", claim.ClaimValue); command.Parameters.AddWithValue("@UserId", user.Id); command.Parameters.AddWithValue("@ClaimID", claim.Id); command.Parameters.AddWithValue("@IsActive", "True"); command.Parameters.AddWithValue("@DisplayLabel", claim.Notes); command.Parameters.AddWithValue("@Discriminator", "ApplicationUserClaim"); command.Parameters.AddWithValue("@User_Id", user.Id); int _result = command.ExecuteNonQuery(); // Check Error if (_result < 0) { Console.WriteLine("Error inserting data into Database!"); } } } connection.Close(); } //foreach (var claim in Claims) //Send confirmation mail to user and admin string email = supplier.Email; string username = _supplier.UserName; string adminemail = ConfigurationManager.AppSettings["adminemail"].ToString(); string admintemple = ConfigurationManager.AppSettings["admintemple"].ToString(); string subject = ConfigurationManager.AppSettings["subject"].ToString(); string AdminUserName = ConfigurationManager.AppSettings["adminusername"].ToString(); var sendemail = new EmailService.Service.EmailService(); sendemail.SendEmail(email, "ForAdmin.html", "verfication", username); sendemail.SendEmail(adminemail, admintemple, subject, AdminUserName); this.AddNotification("Created successfully.", NotificationType.SUCCESS); return(RedirectToAction("Index")); } else { AddErrors(result); } } ViewBag.PlanID = new SelectList(db.Plans, "Id", "PlanName", supplier.PlanID); var allplans = db.Plans.Where(x => x.IsActive == true).Include(x => x.Features).ToList(); ViewBag.allplans = allplans; return(View(supplier)); } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; ViewBag.PlanID = new SelectList(db.Plans, "Id", "PlanName", supplier.PlanID); var allplans = db.Plans.Where(x => x.IsActive == true).Include(x => x.Features).ToList(); ViewBag.allplans = allplans; return(View(supplier)); } }