public IActionResult OwnProfile() { var userLoginDetail = userManager.Users.Where(x => x.Email == User.Identity.Name).FirstOrDefault(); var userdetail = _context.AllUser.Where(x => x.Email == userLoginDetail.Email).FirstOrDefault(); OwnProfile ownProfile = new OwnProfile { id = userdetail.id, LastName = userdetail.LastName, Addreaddress = userdetail.Addreaddress, Email = userdetail.Email, City = userdetail.City, MiddleName = userdetail.MiddleName, MobileNo = userdetail.MobileNo, MobileNo2 = userdetail.MobileNo2, Name = userdetail.Name, PaidLeave = userdetail.PaidLeave, Department = userdetail.Deparment, Role = userdetail.Role, ExistingImage = userdetail.UserImage }; ownProfile_transfer = ownProfile; return(View(ownProfile)); }
private string ProcessUploadedFile(OwnProfile ownProfile) { string uniqueFileName = null; if (ownProfile.EmployeePicture != null) { string uploadsFolder = Path.Combine(webHostEnvironment.WebRootPath, "Uploads"); uniqueFileName = Guid.NewGuid().ToString() + "_" + ownProfile.EmployeePicture.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); using (var fileStream = new FileStream(filePath, FileMode.Create)) { ownProfile.EmployeePicture.CopyTo(fileStream); } } return(uniqueFileName); }
public async Task <IActionResult> OwnProfile(OwnProfile ownProfile) { //var userLoginDetail = userManager.Users.Where(x => x.Email == User.Identity.Name).FirstOrDefault(); //var userdetail = _context.AllUser.Where(x => x.Email == userLoginDetail.Email).FirstOrDefault(); if (ModelState.IsValid) { string uniqueFileName = ProcessUploadedFile(ownProfile); AllUser allUser = new AllUser { id = ownProfile.id, LastName = ownProfile.LastName, Addreaddress = ownProfile.Addreaddress, Email = User.Identity.Name, City = ownProfile.City, MiddleName = ownProfile.MiddleName, MobileNo = ownProfile.MobileNo.ToString(), MobileNo2 = ownProfile.MobileNo2.ToString(), Name = ownProfile.Name, PaidLeave = ownProfile_transfer.PaidLeave, Deparment = ownProfile_transfer.Department, Role = ownProfile_transfer.Role, UserImage = uniqueFileName }; try { _context.Update(allUser); await _context.SaveChangesAsync(); return(RedirectToAction(controllerName: "common", actionName: "OwnProfile")); } catch (DbUpdateConcurrencyException) { return(View(ownProfile)); } } return(View(ownProfile)); }
public HttpResponseMessage GetOwnProfile() { BackendUserService buservice = new BackendUserService(); UsersMailModel model = new UsersMailModel(); string UserName = MySecurityProvider.CurrentPrincipal.MyIdentity.UserName; BackendUser _bUser = null; try { if (!(SessionManager <BackendUser> .exist(Com.Delta.Web.Session.SessionKeys.BACKEND_USER))) { _bUser = (BackendUser)buservice.GetByUserName(MySecurityProvider.CurrentPrincipal.MyIdentity.UserName); SessionManager <BackendUser> .set(Com.Delta.Web.Session.SessionKeys.BACKEND_USER, _bUser); } else { _bUser = SessionManager <BackendUser> .get(Com.Delta.Web.Session.SessionKeys.BACKEND_USER); } if (_bUser != null) { OwnProfile p = new OwnProfile(); p.Cognome = _bUser.Cognome; p.Department = _bUser.Department; p.Domain = _bUser.Domain; p.CodiceFiscale = _bUser.CodiceFiscale; if (_bUser.MappedMails != null && _bUser.MappedMails.Count > 0) { p.MappedMails = new List <CasellaMail>(); List <CasellaMail> l = new List <CasellaMail>(); foreach (BackEndUserMailUserMapping b in _bUser.MappedMails) { CasellaMail m = new CasellaMail { idMail = b.Id.ToString(), emailAddress = b.Casella }; l.Add(m); } p.MappedMails = l; } p.Nome = _bUser.Nome; p.RoleMail = _bUser.RoleMail; p.RoleMailDesription = (_bUser.RoleMail == 0) ? "Utente" : "Amministratore"; p.UserId = (int)_bUser.UserId; p.UserName = _bUser.UserName; p.UserRole = _bUser.UserRole; p.Password = string.Empty; var roleStore = new RoleStore(); var roles = roleStore.GetRolesByUserId((int)_bUser.UserId).Result; p.Roles = roles; model.OwnProfiles = new List <OwnProfile>(); model.OwnProfiles.Add(p); model.success = "true"; model.Totale = "1"; } else { model.success = "false"; model.message = "Utente non collegato a caselle di posta"; } } catch (Exception ex) { if (!ex.GetType().Equals(typeof(ManagedException))) { ErrorLogInfo error = new ErrorLogInfo(); error.freeTextDetails = ex.Message; error.logCode = "ERR_U002"; error.loggingAppCode = "PEC"; error.loggingTime = System.DateTime.Now; error.uniqueLogID = System.DateTime.Now.Ticks.ToString(); log.Error(error); model.message = ex.Message; model.success = "false"; } else { model.message = ex.Message; model.success = "false"; } } return(this.Request.CreateResponse <UsersMailModel>(HttpStatusCode.OK, model)); }