示例#1
0
        public ActionResult UpdatePicture(long drugFamilyId, uint catalogId, uint producerId, HttpPostedFileBase uploadedFile)
        {
            var drugPicture = new DrugFormPicture();
            var ext         = uploadedFile == null ? "" : new FileInfo(uploadedFile.FileName).Extension;

            if (ext == "" || (ext != ".jpg" && ext != ".jpeg"))
            {
                ErrorMessage("Данный файл не может быть использован: допустимые форматы .jpg, .jpeg");
                return(RedirectToAction("DisplayForms", new { id = drugFamilyId }));
            }
            if (uploadedFile != null && uploadedFile.ContentLength > 550000)
            {
                ErrorMessage("Данный файл не может быть использован: допустимый вес файла 500 кбайт.");
                return(RedirectToAction("DisplayForms", new { id = drugFamilyId }));
            }

            var fileInDb = FileManager.SaveFile(DB2, uploadedFile, EntityType.DrugFormPicture);
            var photo    =
                DbSession.Query <DrugFormPicture>().FirstOrDefault(x => x.CatalogId == catalogId && x.ProducerId == producerId);

            if (photo == null)
            {
                photo            = new DrugFormPicture();
                photo.CatalogId  = catalogId;
                photo.ProducerId = producerId;
                DbSession.Save(photo);
            }

            var model = ccntx.Catalog.First(x => x.Id == catalogId);

            var dl = new CatalogLog()
            {
                After                 = fileInDb.ToString(),
                Before                = photo?.PictureKey?.ToString() ?? "",
                ObjectReference       = catalogId,
                ObjectReferenceNameUi = model.Name,
                Type           = (int)CatalogLogType.Photo,
                LogTime        = DateTime.Now,
                OperatorHost   = CurrentUser.IP,
                UserId         = CurrentUser.ID_LOG,
                PropertyName   = "PictureKey",
                PropertyNameUi = "Изображение",
                NameId         = drugFamilyId,
                ProducerId     = producerId
            };

            DB.CatalogLog.Add(dl);
            DB.SaveChanges();
            SuccessMessage("Замена изображения предложена");
            return(RedirectToAction("DisplayForms", new { id = drugFamilyId }));
        }
示例#2
0
        /// <summary>
        /// Отправляет запрос на правку описания препарата
        /// </summary>
        /// <param name="familyId">идентификатор по таблице catalognames</param>
        /// <param name="field">имя поля</param>
        /// <param name="value">значение поля</param>
        /// <returns></returns>
        public JsonResult EditDescriptionField(long familyId, string field, string value)
        {
            var drugfamily = ccntx.catalognames.Single(x => x.Id == familyId);
            var model      = ccntx.Descriptions.SingleOrDefault(x => x.Id == drugfamily.DescriptionId);

            // если описания нет - создаем его
            if (model == null)
            {
                model = new Descriptions()
                {
                    Name = drugfamily.Name
                };
                ccntx.Descriptions.Add(model);
                ccntx.SaveChanges();
                drugfamily.DescriptionId = model.Id;
                ccntx.SaveChanges();
            }

            var type = model.GetType();

            if (type.BaseType != null && type.Namespace == "System.Data.Entity.DynamicProxies")
            {
                type = type.BaseType;
            }
            var propertyInfo = type.GetProperty(field);
            var before       = (string)propertyInfo.GetValue(model);
            var displayName  = AttributeHelper.GetDisplayName(type, propertyInfo.Name);

            // пишем в лог для премодерации
            var dl = new CatalogLog()
            {
                After                 = value,
                Before                = before,
                ObjectReference       = model.Id,
                ObjectReferenceNameUi = drugfamily.Name,
                Type           = (int)CatalogLogType.Descriptions,
                LogTime        = DateTime.Now,
                OperatorHost   = CurrentUser.IP,
                UserId         = CurrentUser.ID_LOG,
                PropertyName   = propertyInfo.Name,
                PropertyNameUi = displayName,
                NameId         = familyId
            };

            DB.CatalogLog.Add(dl);
            DB.SaveChanges();

            EmailSender.SendDescriptionChangeMessage(DB, CurrentUser, displayName, drugfamily.Name, before, value);
            return(Json(new { field = field, value = value }));
        }
示例#3
0
        public ActionResult EditForms(long familyId)
        {
            var drugfamily = GetDrugFamilyWithCheck(familyId);

            if (drugfamily == null)
            {
                ErrorMessage("Препарат не найден в ассортименте производителя");
                return(RedirectToAction("Index"));
            }

            ViewData["familyName"]   = drugfamily.Name;
            ViewData["familyId"]     = familyId;
            ViewData["producerName"] = ccntx.Producers.Single(x => x.Id == producerId).Name;

            // формы данного лек.средства из ассортимента данного производителя
            var model  = ccntx.Catalog.Where(x => x.NameId == familyId && !x.Hidden && x.assortment.Any(y => y.ProducerId == producerId)).ToList().OrderBy(x => x.Name);
            var ufName = new string[] { "нет", "да" };
            var regex  = new Regex(@"(?<catalogId>\d+)_(?<field>\w+)", RegexOptions.IgnoreCase);

            // форма возвращает значения для всех элементов. Ищем, что изменилось
            for (int i = 0; i < Request.Form.Count; i++)
            {
                var name = Request.Form.GetKey(i);
                if (regex.IsMatch(name))
                {
                    var catalogId = long.Parse(regex.Match(name).Groups["catalogId"].Value);
                    var field     = regex.Match(name).Groups["field"].Value;
                    var after     = bool.Parse(Request.Form.GetValues(i)[0]);
                    // одна строка из каталога, модель - коллекция строк
                    var row  = model.Single(x => x.Id == catalogId);
                    var type = row.GetType();
                    if (type.BaseType != null && type.Namespace == "System.Data.Entity.DynamicProxies")
                    {
                        type = type.BaseType;
                    }

                    var propertyInfo = type.GetProperty(field);
                    var before       = (bool)propertyInfo.GetValue(row);
                    if (after != before)
                    {
                        var displayName = AttributeHelper.GetDisplayName(type, propertyInfo.Name);
                        propertyInfo.SetValue(row, after);
                        // пишем в лог для премодерации
                        var dl = new CatalogLog()
                        {
                            After                 = after.ToString(),
                            Before                = before.ToString(),
                            ObjectReference       = row.Id,
                            ObjectReferenceNameUi = row.Name,
                            Type           = (int)CatalogLogType.PKU,
                            LogTime        = DateTime.Now,
                            OperatorHost   = CurrentUser.IP,
                            UserId         = CurrentUser.ID_LOG,
                            PropertyName   = propertyInfo.Name,
                            PropertyNameUi = displayName,
                            NameId         = familyId,
                            ProducerId     = producerId
                        };
                        DB.CatalogLog.Add(dl);
                        DB.SaveChanges();

                        EmailSender.SendCatalogChangeMessage(DB, CurrentUser, displayName, row.Name, ufName[Convert.ToInt32(before)], ufName[Convert.ToInt32(after)]);
                    }
                }
            }
            return(View("DisplayForms", model));
        }