public async Task <IActionResult> Reset([FromBody] ResetPwdViewModel viewModel) { if (CurrentUser.Id == viewModel.Id) { var loader = new Loader <User>() { Id = CurrentUser.Id }; await DataHandler.Execute(loader); if (loader.Result != null && loader.Result.EncryptedPwd == EncryptHelper.Encrypt(viewModel.Current)) { loader.Result.EncryptedPwd = EncryptHelper.Encrypt(viewModel.Replacement); var persist = new Persist <User> { Model = loader.Result }; await DataHandler.Execute(persist); if (persist.Confirm.Success) { await DataHandler.Commit(); } return(Ok(ConfirmViewModel.CreateFromConfirm(persist.Confirm))); } return(Ok(ConfirmViewModel.CreateFailure("Password not correct"))); } return(Unauthorized()); }
public override async Task <IActionResult> Post([FromBody] AttendanceViewModel viewModel) { var model = await Parse(viewModel); if (AuthoriseWrite(model)) { var persist = new Persist <Attendance> { Model = model }; await DataHandler.Execute(persist); await DataHandler.Commit(); return(Ok(ConfirmViewModel.CreateFromConfirm(persist.Confirm))); } return(Unauthorized()); }
public override async Task <IActionResult> Post([FromBody] MsgViewModel viewModel) { var model = await Parse(viewModel); if (AuthoriseWrite(model)) { model.Files = viewModel.Files.Select(f => f.Id).ToList(); model.Recipients = viewModel.Recipients.Select(f => f.Id).ToList(); var persist = new Persist <Msg> { Model = model }; await DataHandler.Execute(persist); if (persist.Confirm.Success) { await DataHandler.Commit(); } if (string.IsNullOrEmpty(viewModel.Id) || viewModel.ForceNotify) { foreach (var recipient in model.Recipients) { var loader = new UserById() { Id = recipient }; await DataHandler.Execute(loader); var notify = new SimpleNotify { CloudHandler = CloudHandler, DataHandler = DataHandler, CurrentUser = loader.Result, LogicHandler = LogicHandler, Model = persist.Model, TemplateName = "message" }; await LogicHandler.Execute(notify); } } return(Ok(ConfirmViewModel.CreateFromConfirm(persist.Confirm))); } return(Unauthorized()); }
public override async Task <IActionResult> Post([FromBody] UserViewModel viewModel) { var name = string.Empty; if (!string.IsNullOrEmpty(viewModel.Id)) { var original = await Load(viewModel.Id); name = original.Name; } var model = await Parse(viewModel); if (AuthoriseWrite(model)) { if (!string.IsNullOrEmpty(viewModel.Password)) { model.EncryptedPwd = EncryptHelper.Encrypt(viewModel.Password); } model.EncryptedPhone = viewModel.Phone; var image = new CheckProfileImage { Model = model }; await LogicHandler.Execute(image); var persist = new UserSave { Model = model, Original = name }; await DataHandler.Execute(persist); if (persist.Confirm.Success) { await DataHandler.Commit(); } return(Ok(ConfirmViewModel.CreateFromConfirm(persist.Confirm))); } return(Unauthorized()); }
public override async Task <IActionResult> Post([FromBody] TenantViewModel viewModel) { var name = string.Empty; if (!string.IsNullOrEmpty(viewModel.Id)) { var original = await Load(viewModel.Id); name = original.Name; } var model = await Parse(viewModel); if (AuthoriseWrite(model)) { if (string.IsNullOrEmpty(model.Id)) { model.AuthorId = CurrentUser.Id; model.AuthorName = CurrentUser.Name; model.EntryKey = StringHelper.GenerateCode(10).ToLower(); } var image = new CheckProfileImage { Model = model }; await LogicHandler.Execute(image); var persist = new TenantSave { Model = model, Original = name }; await DataHandler.Execute(persist); if (persist.Confirm.Success) { await DataHandler.Commit(); } return(Ok(ConfirmViewModel.CreateFromConfirm(persist.Confirm))); } return(Unauthorized()); }