コード例 #1
0
        public async Task <ActionResult> Delete(int?id, [Bind(Include = "Id")] ContactDeleteViewModel deleteModel)
        {
            var req = new ContactDeleteRequest {
                Id = id ?? deleteModel.Id, Deleter = "FakeUserForDeletionTest"
            };

            var result = await _contactRepository.DeleteContactAsync(req);

            if (result.Success)
            {
                result.DeletedId = id.GetValueOrDefault();
                this.AddToastMessage(@Resource.Resource.Toast_Success, @Resource.Resource.DeleteContact_Toast_Success, ToastType.Success);

                return(RedirectToAction("Deleted", result));
            }

            var vm = new GenericErrorVM {
                ErrorMessage = result.Message
            };

            this.AddToastMessage(@Resource.Resource.DeleteContact_Toast_Failure, result.Message, ToastType.Success);

            Log.Error(null, result.Message);

            return(View("../GenericError/GenericError", vm));
        }
コード例 #2
0
        public async Task <ActionResult> Edit(int id)
        {
            var result = await _contactRepository.GetContactByIdAsync(id);

            if (result.Success)
            {
                var vm = result.Contact.ConvertToViewModel();

                return(View(vm));
            }
            else
            {
                var vm = new GenericErrorVM {
                    ErrorMessage = result.Message
                };
                Log.Error(null, result.Message);
                return(View("../GenericError/GenericError", vm));
            }
        }
コード例 #3
0
        public async Task <ActionResult> Edit(int?id, [Bind(Include = "FirstName, LastName, EMail, TelephoneNumber_Entry")] ContactViewModel editModel)
        {
            var req = new ContactUpdateRequest
            {
                Id                    = id ?? editModel.Id,
                FirstName             = editModel.FirstName,
                LastName              = editModel.LastName,
                EMail                 = editModel.EMail,
                TelephoneNumber_Entry = editModel.TelephoneNumber_Entry,
                Updater               = "SystemFakeUser"
            };

            if (ModelState.IsValid)
            {
                var result = await _contactRepository.UpdateContactAsync(req.Id, req);

                if (result.Success)
                {
                    this.AddToastMessage(@Resource.Resource.Toast_Success,
                                         @Resource.Resource.UpdateContact_Toast_Success, ToastType.Success);

                    return(View(result.Contact.ConvertToViewModel()));
                }

                var vm = new GenericErrorVM {
                    ErrorMessage = result.Message
                };

                this.AddToastMessage(result.Message, @Resource.Resource.UpdateContact_Toast_Failure, ToastType.Error);

                Log.Error(null, result.Message);

                return(View("../GenericError/GenericError", vm));
            }
            else
            {
                return(View(editModel));
            }
        }
コード例 #4
0
        public async Task <ActionResult> Delete(int id)
        {
            var result = await _contactRepository.GetContactByIdAsync(id);

            if (result.Success)
            {
                var vm = result.Contact.ConvertToDeleteViewModel();

                Log.Warning(null, "Deleted contact - Name: [ " + result.Contact.FirstName + "], Surname: [ " + result.Contact.LastName + " ]");

                return(View(vm));
            }
            else
            {
                var vm = new GenericErrorVM {
                    ErrorMessage = result.Message
                };

                Log.Error(null, result.Message);

                return(View("../GenericError/GenericError", vm));
            }
        }