Esempio n. 1
0
        public ActionResult Edit(long?var_id, string var_name, string var_friendly_name, string var_value, string var_type, string var_comment, string var_group, FormCollection form)
        {
            //
            bool file_is_change = false;

            foreach (string fileName in Request.Files)
            {
                HttpPostedFileBase file = Request.Files[fileName] as HttpPostedFileBase;

                if (file.ContentLength == 0 || file.FileName == "blob" || file.FileName == "var_value")
                {
                    continue;
                }

                file_is_change = true;

                // save in db

                long file_id; string file_desc = file.FileName; int file_size = file.ContentLength; string file_extension = Path.GetExtension(file.FileName);

                using (FileRepository database = new FileRepository())
                {
                    file_id = database.CreateGlobalID();

                    database.Save(file_id, file_extension, null, file.FileName, file.ContentLength, string.Empty);
                }

                // save in file system

                try
                {
                    file.SaveAs(Path.Combine(Server.MapPath("~/content/cms/files"), string.Format("{0}{1}", file_id, file_extension)));

                    var_value = string.Format("/content/cms/files/{0}{1}", file_id, file_extension);
                }
                catch
                {
                    using (FileRepository database = new FileRepository())
                    {
                        database.Remove(file_id);
                    }
                }
            }

            //

            var_group = var_group.Replace(",", string.Empty);

            using (VariableRepository variable_repository = new VariableRepository())
            {
                if (var_id.HasValue)
                {
                    var v = variable_repository.GetByID(var_id.Value);

                    variable_repository.Update(var_id.Value, var_name, var_friendly_name, (file_is_change && v.var_type == "Файл" ? var_value : (v.var_type == "Файл" ? v.var_value : var_value)), var_comment, var_group, CurrentUser.user_domain);
                }
                else
                {
                    var_id = variable_repository.CreateGlobalID();

                    string new_var_name = Transliterator.Translite(var_friendly_name);

                    if (variable_repository.Exists(new_var_name, CurrentUser.user_domain))
                    {
                        new_var_name = new_var_name + "-" + var_id.ToString();
                    }

                    variable_repository.Create(var_id.Value, new_var_name, var_friendly_name, var_value, var_type, var_comment, var_group, CurrentUser.user_domain);
                }
            }

            return(RedirectToAction("Index"));
        }