Exemplo n.º 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 }));
        }
Exemplo n.º 2
0
        private int DrugFormPicture(uint catalogId, uint producerId, uint drugFamilyId)
        {
            var fileInDb = session.Query <ProducerInterfaceCommon.Models.MediaFiles>().FirstOrDefault() ??
                           new ProducerInterfaceCommon.Models.MediaFiles()
            {
                EntityType = EntityType.DrugFormPicture, ImageName = "newFile", ImageSize = 101613, ImageType = "image/jpeg"
            };

            session.Save(fileInDb);
            var photo = new DrugFormPicture();

            photo.CatalogId  = catalogId;
            photo.ProducerId = producerId;
            photo.PictureKey = fileInDb.Id;
            session.Save(photo);
            return(fileInDb.Id);
        }
        private int ProposalOfDrugFormPictureAdd(uint catalogId, uint producerId, uint drugFamilyId)
        {
            var fileInDb = session.Query <MediaFiles>().FirstOrDefault() ??
                           new ProducerInterfaceCommon.Models.MediaFiles()
            {
                EntityType = EntityType.DrugFormPicture,
                ImageName  = "newFile",
                ImageSize  = 101613,
                ImageType  = "image/jpeg"
            };

            session.Save(fileInDb);
            var photo = new DrugFormPicture();

            photo.CatalogId  = catalogId;
            photo.ProducerId = producerId;
            session.Save(photo);

            var model = session.Query <Catalog>().First(x => x.Id == catalogId);

            var dl = new CatalogLog()
            {
                After                 = fileInDb.Id.ToString(),
                Before                = photo?.PictureKey?.ToString(),
                ObjectReference       = catalogId,
                ObjectReferenceNameUi = model.Name,
                Type           = (int)CatalogLogType.Photo,
                LogTime        = DateTime.Now,
                OperatorHost   = "0.0.0.1",
                UserId         = session.Query <ProducerInterfaceCommon.Models.Account>().First(s => s.Login.IndexOf("@") != -1).Id,
                PropertyName   = "PictureKey",
                PropertyNameUi = "Изображение",
                NameId         = drugFamilyId,
                ProducerId     = producerId
            };

            session.Save(dl);
            return(fileInDb.Id);
        }