Exemplo n.º 1
0
        public ActionResult Index(Default @default)
        {
            try
            {
                var logoName   = Path.GetFileName(@default.file.FileName);
                var folderPath = Server.MapPath("~/images/defaults");
                if (!Directory.Exists(folderPath))
                {
                    Directory.CreateDirectory(folderPath);
                }
                string path = Path.Combine(folderPath, logoName);
                @default.file.SaveAs(path);
                @default.Logo = "images/defaults/" + logoName;
            }
            catch (System.Exception)
            {
            }

            try
            {
                if (ModelState.IsValid)
                {
                    @default.CreatedBy = LogedInUser.Id;
                    defaultService.AddOrUpdate(@default);

                    Session["_culture"] = @default.Language;

                    var responseModel = new ResponseModel
                    {
                        StatusCode = (int)HttpStatusCode.OK,
                        MessageAr  = @default.Id > 0 ? AppResource.UpdatedSuccessfully : AppResource.SavedSuccessfully
                    };
                    return(Json(responseModel, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    var responseModel = new ResponseModel
                    {
                        StatusCode = (int)HttpStatusCode.InternalServerError,
                        MessageAr  = AppResource.ChangesNotSaved
                    };
                    return(Json(responseModel, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                var responseModel = new ResponseModel
                {
                    StatusCode = (int)HttpStatusCode.InternalServerError,
                    MessageAr  = AppResource.ChangesNotSaved
                };
                return(Json(responseModel, JsonRequestBehavior.AllowGet));
            }
        }