Esempio n. 1
0
        public async Task <IActionResult> Edit(StatementEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                var statement = Repository.Statements.FindByCondition(q => q.Id == model.Id).FirstOrDefault();

                var newStatement = new Statement
                {
                    Id          = model.Id,
                    Title       = model.Title,
                    Description = model.Description,
                    PhoneNumber = model.PhoneNumber
                };

                if (model.Photo != null)
                {
                    if (model.ExistingPhotoPath != null)
                    {
                        string filePath = Path.Combine(HostingEnvironment.WebRootPath, "images", model.ExistingPhotoPath);
                        System.IO.File.Delete(filePath);
                    }
                    newStatement.PhotoPath = ProcessUploadedFile(model);
                }


                await Repository.Statements.UpdateStatementAsync(statement, newStatement);

                return(RedirectToAction("List"));
            }
            return(View(model));
        }
Esempio n. 2
0
        public IActionResult Edit(Guid Id)
        {
            var statement = Repository.Statements.FindByCondition(q => q.Id == Id).FirstOrDefault();

            StatementEditViewModel statementEditViewModel = new StatementEditViewModel
            {
                Id = statement.Id,
                ExistingPhotoPath = statement.PhotoPath,
                Title             = statement.Title,
                Description       = statement.Description,
                PhoneNumber       = statement.PhoneNumber
            };

            return(View(statementEditViewModel));
        }