/// <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 })); }
private void Apply(long id) { var item = DB.CatalogLog.Single(x => x.Id == id); switch (item.TypeEnum) { case CatalogLogType.Descriptions: var description = ccntx.Descriptions.Single(x => x.Id == item.ObjectReference); SetValue(description, item.PropertyName, item.After); break; case CatalogLogType.MNN: var drugfamily = ccntx.catalognames.Single(x => x.Id == item.ObjectReference); SetValue(drugfamily, item.PropertyName, item.After); break; case CatalogLogType.PKU: var catalog = ccntx.Catalog.Single(x => x.Id == item.ObjectReference); SetValue(catalog, item.PropertyName, item.After); break; case CatalogLogType.Photo: var photo = DbSession.Query <DrugFormPicture>() .First(x => x.CatalogId == item.ObjectReference && x.ProducerId == item.ProducerId); photo.PictureKey = Convert.ToInt32(item.After); DbSession.SaveOrUpdate(photo); DbSession.Transaction.Commit(); break; } ccntx.SaveChanges(); item.Apply = (sbyte)ApplyRedaction.Applied; item.AdminId = CurrentUser.Id; item.DateEdit = DateTime.Now; DB.SaveChanges(); // SendMessage }