public AddCompanyResponse addCompIndvidualModel(AddCompanyIndPayload comp, IConfiguration _config, IHostingEnvironment env) { try { using (var db = new TrippleNTDBContext()) { var checkcompany = db.Company.Where(o => o.PhoneNumber == comp.phoneNumber || o.Email == comp.email || o.Rcno == comp.rcNo).FirstOrDefault(); if (checkcompany != null) { return(checkcompany.PhoneNumber == comp.phoneNumber? new AddCompanyResponse { status = "failed", msg = "Phone Number Already Exists" } :comp.rcNo == checkcompany.Rcno ? new AddCompanyResponse { status = "failed", msg = "Invalid Company Reg Number" }: new AddCompanyResponse { status = "failed", msg = "Email Already Exists" }); } var newcomp = new Company(); newcomp.Name = comp.companyName; newcomp.Email = comp.email; newcomp.PhoneNumber = comp.phoneNumber; newcomp.Type = 1; newcomp.RegDate = DateTime.Now; newcomp.Location = comp.location; newcomp.State = comp.state; db.Company.Add(newcomp); db.SaveChanges(); var password = comp.password; var staff = new CompanyStaff(); staff.CompanyId = newcomp.CompanyId; staff.DateCreated = DateTime.Now; staff.UseStatus = false; staff.Password = Utility.Encryptor.EncodePasswordMd5(password); staff.UserType = "Admin"; db.CompanyStaff.Add(staff); var staff1 = new CompanyStaff(); staff.CompanyId = newcomp.CompanyId; staff1.DateCreated = DateTime.Now; staff1.UseStatus = false; staff1.Password = Utility.Encryptor.GeneratePassword(6); staff1.UserType = "User"; db.CompanyStaff.Add(staff); db.SaveChanges(); var msg = "Hello, " + comp.companyName + ", <br> We are glad to have you on our EduFund crowdfunding Platform. <br> Kindly See your credentials below <br><b>User Id: " + newcomp.PhoneNumber + "</b><br> <b> Password: "******" </b><br><br>#ChangeTheWorldWithYourSpareChange <br><br>Regards,<br> Admin Edufund"; Utility.SendMail.Send("Welcome to EduFund", msg, newcomp.Email, _config); return(new AddCompanyResponse { status = "success", msg = "Company Created Successfully" }); } } catch (Exception ex) { new Utility.LogWriter(ex.Message + " " + ex.InnerException, env); return(new AddCompanyResponse { status = "failed", msg = "Something Went Wrong Try again Later" }); } }
// [MessageHandlers.JWTAuthHandler] public AddCompanyResponse AddCompanyInd(AddCompanyIndPayload company) { return(new AddCompanyToDb().addCompIndvidualModel(company, configuration, _hosting)); }