Exemplo n.º 1
0
        public ActionResult EditService(int id)
        {
            CommonDataService cds = new CommonDataService();

            CommonModel cm = new CommonModel();

            cm = cds.GenerateCommonModel();
            Session["FaceBook"] = cm.FaceBook;
            Session["Twitter"] = cm.Twitter;
            Session["Youtube"] = cm.Youtube;
            Session["Instagram"] = cm.Instagram;
            Session["PhoneNumber"] = cm.PhoneNumber;
            Session["Email"] = cm.Email;
            Session["ShoppingHours"] = cm.ShoppingHours;
            ServicesModel model = new ServicesModel();
            ServicesDataService dataservice = new ServicesDataService();
            try
            {
                model = dataservice.GetServicesModelByServiceId(id);

                return View(model);
            }
            catch (Exception ex)
            {

                throw ex;
            }
            finally
            {
                model = null;
                dataservice = null;
            }
        }
Exemplo n.º 2
0
        public ActionResult EditService(ServicesModel model)
        {
            CommonDataService cds = new CommonDataService();

            CommonModel cm = new CommonModel();

            cm = cds.GenerateCommonModel();
            Session["FaceBook"] = cm.FaceBook;
            Session["Twitter"] = cm.Twitter;
            Session["Youtube"] = cm.Youtube;
            Session["Instagram"] = cm.Instagram;
            Session["PhoneNumber"] = cm.PhoneNumber;
            Session["Email"] = cm.Email;
            Session["ShoppingHours"] = cm.ShoppingHours;
            ServicesDataService dataservice = new ServicesDataService();
            string serviceId = (string)Request.Form["edit_ServicesId"];
            string imageString = (string)Request.Form["edit_ImageString"];
            string serviceName = (string)Request.Form["edit_ServiceName"];
            try
            {
                if (ModelState.IsValid)
                {
                    WebImage photo = null;
                    var newFileName = "";
                    var imagePath = "";

                    photo = WebImage.GetImageFromRequest();
                    if (photo != null)
                    {
                        newFileName = Guid.NewGuid().ToString() + "_" +
                            Path.GetFileName(photo.FileName);
                        imagePath = @"Contents\Images\Services\" + newFileName;

                        photo.Save(@"~\" + imagePath);
                        model.ServicesId = int.Parse(serviceId);
                        model.ImageString = imagePath;

                    }
                    else
                    {
                        model.ServicesId = int.Parse(serviceId);
                        model.ImageString = imageString;
                    }

                    dataservice.UpdateService(model);
                    return RedirectToAction("Edit", "Services");
                }
                else
                {
                    model.ServicesId = int.Parse(serviceId);
                    model.ImageString = imageString;
                    return View(model);
                }
            }
            catch (Exception ex)
            {

                throw ex;
            }
            finally
            {
                model = null;
                dataservice = null;
            }
        }