public ValidUser AddNewUser([FromBody] TotalUser User) { String resp; ValidUser DemoUser = new ValidUser(); try { //ViewSocietyUsers var context = new NestinDBEntities(); using (var dbContextTransaction = context.Database.BeginTransaction()) { var users = (from USER in context.TotalUsers where USER.MobileNo == User.MobileNo || USER.EmailId == User.EmailId select USER); if (users.Count() > 0) { DemoUser.result = "Duplicate"; DemoUser.message = "Mobile or Email Id is in use"; //return BadRequest(); //resp = "{\"Response\":\"Fail\"}"; //var response = Request.CreateResponse(HttpStatusCode.BadRequest); //response.Content = new StringContent(resp, System.Text.Encoding.UTF8, "application/json"); //return response; return(DemoUser); } else { String encryptPwd = ValidateUser.EncryptPassword(User.EmailId, User.Password); User.Password = encryptPwd; // Add User context.TotalUsers.Add(User ); context.SaveChanges(); context.SaveChanges(); dbContextTransaction.Commit(); User.Password = ""; DemoUser.UserData = User; DemoUser.result = "Ok"; var sub = "Your User Login is created"; var EmailBody = "Dear User \n You have successfully Registered with Nestin.Online. Please select your Role from Role Page"; var smsBody = "Welcome to Nestin.online. your Registration is succesfull."; Utility.SendMail(User.EmailId, sub, EmailBody); Utility.sendSMS2Resident(smsBody, User.MobileNo); //return Ok(); //resp = "{\"Response\":\"Ok\"}"; //var response = Request.CreateResponse(HttpStatusCode.OK); //response.Content = new StringContent(resp, System.Text.Encoding.UTF8, "application/json"); return(DemoUser); } } } catch (Exception ex) { //return InternalServerError(ex.InnerException); //resp = "{\"Response\":\"Fail\"}"; //var response = Request.CreateResponse(HttpStatusCode.InternalServerError); //response.Content = new StringContent(resp, System.Text.Encoding.UTF8, "application/json"); //return response; DemoUser.result = "Fail"; DemoUser.message = "Server Error"; return(DemoUser); } }
public ValidUser IsValid([FromBody] ValidateUser ValUser) { Log.log("Reached Validate At " + DateTime.Now.ToString()); var ValidUser = new ValidUser(); try { using (var context = new NestinDBEntities()) { if (ValUser.Email == null && ValUser.Mobile == null) { Log.log("Both are null " + DateTime.Now.ToString()); ValidUser.result = "Fail"; ValidUser.message = "Email and Maobile are null"; return(ValidUser); } else if (ValUser.Email == null || ValUser.Email == "") { Log.log("one is valid " + DateTime.Now.ToString()); var users = (from USER in context.TotalUsers where USER.MobileNo == ValUser.Mobile select USER).ToList(); if (users.Count() > 0) { ValUser.Email = users.First().EmailId; } else { ValidUser.result = "Fail"; ValidUser.message = "Mobile Number is incorrect"; return(ValidUser); } } String encPwd = ValidateUser.EncryptPassword(ValUser.Email.ToLower(), ValUser.Password); Log.log("Encrypted Password is :" + encPwd + " At " + DateTime.Now.ToString()); var L2EQuery = context.TotalUsers.Where(u => (u.UserLogin.ToLower() == ValUser.Email.ToLower() || u.MobileNo == ValUser.Mobile) && u.Password == encPwd); var user = L2EQuery.FirstOrDefault(); if (user != null) { Log.log(user.FirstName); if (ValUser.RegistrationID != null && ValUser.RegistrationID != "") { var GCM = context.GCMLists; var reg = GCM.Where(g => g.UserId == user.UserID); if (reg.Count() == 0) { GCM.Add(new GCMList { UserId = user.UserID, RegID = ValUser.RegistrationID, Topic = "", }); } else { reg.First().RegID = ValUser.RegistrationID; } context.SaveChanges(); } ValidUser.result = "Ok"; ValidUser.UserData = user; ValidUser.SocietyUser = (from res in context.ViewSocietyUsers where (res.UserID == user.UserID && res.statusID == 2 && DbFunctions.TruncateTime(res.DeActiveDate) > DbFunctions.TruncateTime(DateTime.UtcNow) && DbFunctions.TruncateTime(res.ActiveDate) <= DbFunctions.TruncateTime(DateTime.UtcNow)) select res).ToList(); } else { ValidUser.result = "Fail"; ValidUser.message = "No Valid User"; ValidUser.UserData.FirstName = ""; ValidUser.UserData.LastName = ""; } } } catch (Exception ex) { Log.log(ex.Message); ValidUser.result = "Fail"; ValidUser.message = "Server Error"; ValidUser.UserData.FirstName = ""; ValidUser.UserData.LastName = ""; } return(ValidUser); }
public ValidUser AddUser([FromBody] TotalUser User) { String resp; ValidUser DemoUser = new ValidUser(); try { var context = new NestinDBEntities(); using (var dbContextTransaction = context.Database.BeginTransaction()) { var users = (from USER in context.ViewSocietyUsers where USER.MobileNo == User.MobileNo || USER.EmailId == User.EmailId select USER); if (users.Count() > 0) { DemoUser.result = "Duplicate"; DemoUser.message = "Mobile or Email Id is in use"; //return BadRequest(); //resp = "{\"Response\":\"Fail\"}"; //var response = Request.CreateResponse(HttpStatusCode.BadRequest); //response.Content = new StringContent(resp, System.Text.Encoding.UTF8, "application/json"); //return response; return(DemoUser); } else { String encryptPwd = ValidateUser.EncryptPassword(User.EmailId, User.Password); User.Password = encryptPwd; // Add User context.TotalUsers.Add(User ); context.SaveChanges(); Flat newFlat = new Flat { FlatNumber = User.FirstName.Substring(0, 1) + User.LastName.Substring(0, 1) + User.MobileNo.Substring(7, 3), BHK = 3, Block = User.FirstName.Substring(0, 1), FlatArea = "1200", Floor = Convert.ToInt32(User.MobileNo.Substring(9, 1)), IntercomNumber = Convert.ToInt32(User.MobileNo.Substring(5, 5)), SocietyID = 1, UserID = User.UserID }; // Add Flat context.Flats.Add(newFlat); context.SaveChanges(); SocietyUser demoSocietyUser = new SocietyUser { UserID = User.UserID, SocietyID = 1, ActiveDate = DateTime.UtcNow, CompanyName = "", DeActiveDate = DateTime.UtcNow.AddDays(15), FlatID = newFlat.ID, ModifiedDate = DateTime.UtcNow, ServiceType = 0, Status = 2, Type = "Owner" }; context.SocietyUsers.Add(demoSocietyUser); context.SaveChanges(); dbContextTransaction.Commit(); var socUser = context.ViewSocietyUsers.Where(x => x.ResID == demoSocietyUser.ResID).First(); DemoUser.UserData = User; DemoUser.result = "Ok"; DemoUser.SocietyUser.Add(socUser); var sub = "Your Demo ID is created"; var EmailBody = "Dear User \n You have successfully Registered with Nestin.Online For Demo. You demo will run for 15 days. Please" + "Explore the application and contact us for any further query"; var smsBody = "Welcome to Nestin.online. your demo login is valid for 15 days."; Utility.SendMail(User.EmailId, sub, EmailBody); Utility.sendSMS2Resident(smsBody, User.MobileNo); //return Ok(); //resp = "{\"Response\":\"Ok\"}"; //var response = Request.CreateResponse(HttpStatusCode.OK); //response.Content = new StringContent(resp, System.Text.Encoding.UTF8, "application/json"); return(DemoUser); } } } catch (Exception ex) { //return InternalServerError(ex.InnerException); //resp = "{\"Response\":\"Fail\"}"; //var response = Request.CreateResponse(HttpStatusCode.InternalServerError); //response.Content = new StringContent(resp, System.Text.Encoding.UTF8, "application/json"); //return response; DemoUser.result = "Fail"; DemoUser.message = "Server Error"; return(DemoUser); } }