Ejemplo n.º 1
0
        public ImageLocation SavePhotoForWorkOrder(ImageModel model)
        {
            var workOrder = this.repository.SearchFor <SageWorkOrder>(x => x.WorkOrder == model.IdWorkOrder).SingleOrDefault();

            if (workOrder == null)
            {
                return(null);
            }

            var imagesDb   = repository.SearchFor <SageImageWorkOrder>(x => x.WorkOrder == model.IdWorkOrder).SingleOrDefault();
            var countImage = 1;

            if (imagesDb != null && imagesDb.Images != null)
            {
                countImage = imagesDb.Images.Last().Id + 1;
            }
            else
            {
                imagesDb = new SageImageWorkOrder
                {
                    Images          = new List <ImageLocation>(),
                    WorkOrder       = model.IdWorkOrder,
                    WorkOrderBsonId = workOrder.Id,
                };
            }

            //var pathToImage = Path.Combine(this.httpContextProvider.MapPath(this._urlToFolderPhotoWorkOrders), model.IdWorkOrder.ToString());
            var pathToImage   = _storageProvider.GetPublicUrl(Path.Combine(this._urlToFolderPhotoWorkOrders, model.IdWorkOrder.ToString()));
            var nameBig       = $"{workOrder.WorkOrder}-{countImage}";
            var nameSmall     = $"{small}-{workOrder.WorkOrder}-{countImage}";
            var fileName      = SavePhotoForWorkOrder(model.Image, pathToImage, nameBig, settings.SizeBigPhoto, workOrder, countImage);
            var fileNameSmall = SavePhotoForWorkOrder(model.Image, pathToImage, nameSmall, this.settings.SizeSmallPhoto, workOrder, countImage);
            var maxId         = imagesDb.Images.Any() ? imagesDb.Images.Max(x => x.Id) : 0;
            var image         = new ImageLocation {
                Image = fileNameSmall, BigImage = fileName, Latitude = model.Latitude, Longitude = model.Longitude, Id = maxId + 1, Description = model.Description
            };

            imagesDb.Images.Add(image);
            repository.Add(imagesDb);
            var milliseconds = DateTime.Now.TimeOfDay.TotalMilliseconds;

            image.Image    += $"?{milliseconds}";
            image.BigImage += $"?{milliseconds}";
            _hub.UpdateWorkOrderPicture(imagesDb);
            return(image);
        }
Ejemplo n.º 2
0
        public ActionResult GetWorkOrdersPictures(EditCommentModel model)
        {
            var pictures = _repository.SearchFor <SageImageWorkOrder>(x => x.WorkOrder == model.WorkOrder).SingleOrDefault();

            if (pictures == null)
            {
                return(Error("Edit picture comments failed", $"GetWorkOrdersPictures method SageImageWorkOrder==false."));
            }
            pictures.Images.Find(x => x.Id == model.Id && !x.IsDeleted).Description = model.Comment;
            _repository.Update(pictures);
            _hub.UpdateWorkOrderPicture(pictures);
            return(Success());
        }
Ejemplo n.º 3
0
        public ActionResult RemoveWorkOrderPicture(PictureModel model)
        {
            _log.InfoFormat("Method: DeletePicture. Id: {0}, WorkOrder {1}", model.Id, model.WorkOrder);
            var imageItem = repository.SearchFor <SageImageWorkOrder>(x => x.WorkOrder == model.WorkOrder).FirstOrDefault();

            if (imageItem == null)
            {
                _log.InfoFormat("Workorder {0} images not found", model.WorkOrder);
                return(Error("Workorder images not found", $"There is no SageImageWorkOrder with Workorder {model.WorkOrder}. imageItem == null"));
            }
            var imageId = model.Id.AsInt();
            var image   = imageItem.Images.FirstOrDefault(x => x.Id == imageId);

            if (image != null)
            {
                image.IsDeleted = true;
            }
            //imageItem.Images.Remove(image);
            repository.Update(imageItem);
            _hub.UpdateWorkOrderPicture(imageItem);
            _log.InfoFormat("Image ({0}) deleted. Repository updated", model.Id);
            //  notification.SendNotification(string.Format("Image {0} deleted. Repository updated", model.Id));
            return(Success());
        }