Beispiel #1
0
        public ActionResult Create(Service model)
        {
            try
            {
                model.Id = 0;
                var service = new Service
                {
                    Title = model.Title,
                    TitleR = model.TitleR,
                    TitleEng = model.TitleEng,
                    Description = model.Description == null ? "" : HttpUtility.HtmlDecode(model.Description),
                    DescriptionEng = model.DescriptionEng == null ? "" : HttpUtility.HtmlDecode(model.DescriptionEng),
                    SortOrder = model.SortOrder,
                    Name = string.IsNullOrEmpty(model.Name)
                        ? SiteHelper.UpdatePageWebName(model.Name, model.Title)
                        : SiteHelper.UpdatePageWebName(model.Name)
                };

                var file = Request.Files[0];
                if (file != null && !string.IsNullOrEmpty(file.FileName))
                {
                    string fileName = IOHelper.GetUniqueFileName("~/Content/Images", file.FileName);
                    string filePath = Server.MapPath("~/Content/Images");

                    filePath = Path.Combine(filePath, fileName);
                    GraphicsHelper.SaveOriginalImage(filePath, fileName, file, 1500);
                    service.ImageSource = fileName;
                }
                else
                {
                    service.ImageSource = service.ImageSource ?? "";
                }

                _repository.AddService(service);
            }
            catch (Exception ex)
            {
                TempData["errorMessage"] = ex.Message + (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message) ? ex.InnerException.Message : "");
                return View(model);
            }

            return RedirectToAction("Index");
        }
Beispiel #2
0
        public ActionResult Edit(Service model)
        {
            try
            {
                var service = _repository.GetService(model.Id);
                service.Name = string.IsNullOrEmpty(model.Name)
                   ? SiteHelper.UpdatePageWebName(model.Name, model.Title)
                   : SiteHelper.UpdatePageWebName(model.Name);
                TryUpdateModel(service, new[] { "Title", "TitleR", "TitleEng", "SortOrder" });

                service.Description = model.Description == null ? "" : HttpUtility.HtmlDecode(model.Description);
                service.DescriptionEng = model.DescriptionEng == null ? "" : HttpUtility.HtmlDecode(model.DescriptionEng);

                var file = Request.Files[0];
                if (file != null && !string.IsNullOrEmpty(file.FileName))
                {
                    if (!string.IsNullOrEmpty(service.ImageSource))
                    {
                        ImageHelper.DeleteImage(service.ImageSource);
                    }

                    string fileName = IOHelper.GetUniqueFileName("~/Content/Images", file.FileName);
                    string filePath = Server.MapPath("~/Content/Images");

                    filePath = Path.Combine(filePath, fileName);
                    GraphicsHelper.SaveOriginalImage(filePath, fileName, file, 1500);
                    service.ImageSource = fileName;
                }
                else
                {
                    service.ImageSource = service.ImageSource ?? "";
                }
                _repository.SaveService(service);
            }
            catch (Exception ex)
            {
                TempData["errorMessage"] = ex.Message;
                return View(model);
            }
            return RedirectToAction("Index");
        }
Beispiel #3
0
 public int AddService(Service service)
 {
     _store.Services.Add(service);
     _store.SaveChanges();
     return service.Id;
 }
Beispiel #4
0
 public void SaveService(Service service)
 {
     _store.SaveChanges();
 }