Пример #1
0
        /// <summary>
        /// update project part drawing
        /// </summary>
        /// <param name="drawing"></param>
        /// <returns></returns>
        public OperationResult UpdateProjectPartDrawing(ProjectPartDrawing drawing)
        {
            var operationResult = new OperationResult();

            var existingProjectPartDrawing = GetProjectPartDrawing(drawing.ProjectPartDrawingId);

            if (existingProjectPartDrawing != null)
            {
                try
                {
                    _db.ProjectPartDrawing.Attach(existingProjectPartDrawing);

                    _db.Entry(existingProjectPartDrawing).CurrentValues.SetValues(drawing);

                    _db.SaveChanges();

                    operationResult.Success = true;
                    operationResult.Message = "Success";
                }
                catch (Exception ex)
                {
                    operationResult.Success = false;
                    operationResult.Message = "Error";
                    logger.ErrorFormat("An error occurred while updating project part drawing. {0}", ex.ToString());
                }
            }
            else
            {
                operationResult.Success = false;
                operationResult.Message = "Unable to find project part drawing to update";
            }

            return(operationResult);
        }
Пример #2
0
        /// <summary>
        /// convert posted drawing to project part drawing
        /// </summary>
        /// <param name="drawing"></param>
        /// <returns></returns>
        public ProjectPartDrawing ConvertToDomain(HttpPostedFileBase drawing)
        {
            ProjectPartDrawing projectPartDrawing = new ProjectPartDrawing();

            byte[] tempFile = new byte[drawing.ContentLength];

            var trimmedFileName = string.Empty;

            if (drawing.FileName.EndsWith("png"))
            {
                trimmedFileName = drawing.FileName.Replace(".png", "");
            }
            else if (drawing.FileName.EndsWith("jpg"))
            {
                trimmedFileName = drawing.FileName.Replace(".jpg", "");
            }
            else if (drawing.FileName.EndsWith("pdf"))
            {
                trimmedFileName = drawing.FileName.Replace(".pdf", "");
            }

            projectPartDrawing.RevisionNumber = trimmedFileName;
            projectPartDrawing.Type           = drawing.ContentType;
            projectPartDrawing.Length         = drawing.ContentLength;
            projectPartDrawing.Content        = tempFile;

            return(projectPartDrawing);
        }
Пример #3
0
        /// <summary>
        /// save project part drawing
        /// </summary>
        /// <param name="newProjectPartDrawing"></param>
        /// <returns></returns>
        public OperationResult SaveProjectPartDrawing(ProjectPartDrawing newProjectPartDrawing)
        {
            var operationResult = new OperationResult();

            try
            {
                var existingProjectPartDrawing = _db.ProjectPartDrawing.FirstOrDefault(x => x.RevisionNumber.ToLower() == newProjectPartDrawing.RevisionNumber.ToLower() && x.ProjectPartId == newProjectPartDrawing.ProjectPartId);

                if (existingProjectPartDrawing == null)
                {
                    var insertedDrawing = _db.ProjectPartDrawing.Add(newProjectPartDrawing);

                    _db.SaveChanges();

                    operationResult.Success     = true;
                    operationResult.Message     = "Success";
                    operationResult.ReferenceId = insertedDrawing.ProjectPartDrawingId;
                    operationResult.Number      = insertedDrawing.RevisionNumber;
                }
                else
                {
                    operationResult.Success = false;
                    operationResult.Message = "Duplicate Entry";
                }
            }
            catch (Exception ex)
            {
                operationResult.Success = false;
                operationResult.Message = "Error";
                logger.ErrorFormat("An error occurred while saving new project part drawing. {0}", ex.ToString());
            }

            return(operationResult);
        }
Пример #4
0
        /// <summary>
        /// convert project part drawing to pdf
        /// </summary>
        /// <param name="drawing"></param>
        /// <returns></returns>
        public DrawingPdf ConvertToPdf(ProjectPartDrawing drawing)
        {
            DrawingPdf model = new DrawingPdf();

            model.Content        = drawing.Content;
            model.Type           = drawing.Type;
            model.RevisionNumber = drawing.RevisionNumber;

            return(model);
        }
Пример #5
0
        /// <summary>
        /// convert part drawing to project part drawing
        /// </summary>
        /// <param name="drawing"></param>
        /// <returns></returns>
        public ProjectPartDrawing ConvertToDomain(PartDrawing drawing)
        {
            ProjectPartDrawing projectPartDrawing = new ProjectPartDrawing();

            projectPartDrawing.RevisionNumber = drawing.RevisionNumber;
            projectPartDrawing.Type           = drawing.Type;
            projectPartDrawing.Length         = drawing.Length;
            projectPartDrawing.Content        = drawing.Content;

            return(projectPartDrawing);
        }
Пример #6
0
        /// <summary>
        /// convert project part drawing to view model
        /// </summary>
        /// <param name="drawing"></param>
        /// <returns></returns>
        public DrawingViewModel ConvertToView(ProjectPartDrawing drawing)
        {
            DrawingViewModel model = new DrawingViewModel();

            model.DrawingId      = drawing.ProjectPartDrawingId;
            model.RevisionNumber = (!string.IsNullOrEmpty(drawing.RevisionNumber)) ? drawing.RevisionNumber : "N/A";
            model.LastDate       = drawing.ModifiedDate;
            model.IsProject      = true;

            return(model);
        }
Пример #7
0
        /// <summary>
        /// convert project part drawing to part drawing
        /// </summary>
        /// <param name="projectPartDrawing"></param>
        /// <returns></returns>
        public PartDrawing ConvertToDomain(ProjectPartDrawing projectPartDrawing)
        {
            PartDrawing partDrawing = new PartDrawing();

            partDrawing.RevisionNumber = projectPartDrawing.RevisionNumber;
            partDrawing.Type           = projectPartDrawing.Type;
            partDrawing.Length         = projectPartDrawing.Length;
            partDrawing.Content        = projectPartDrawing.Content;
            partDrawing.IsLatest       = projectPartDrawing.IsLatest;
            partDrawing.IsMachined     = projectPartDrawing.IsMachined;
            partDrawing.IsRaw          = projectPartDrawing.IsRaw;

            return(partDrawing);
        }
Пример #8
0
        /// <summary>
        /// get project part drawing by name
        /// </summary>
        /// <param name="trimmedFileName"></param>
        /// <returns></returns>
        public ProjectPartDrawing GetProjectPartDrawing(string trimmedFileName)
        {
            var partDrawing = new ProjectPartDrawing();

            try
            {
                partDrawing = _db.ProjectPartDrawing.FirstOrDefault(x => x.RevisionNumber == trimmedFileName);
            }
            catch (Exception ex)
            {
                logger.ErrorFormat("An error occurred while getting project part drawing. {0}", ex.ToString());
            }

            return(partDrawing);
        }
Пример #9
0
        /// <summary>
        /// get project part drawing by id
        /// </summary>
        /// <param name="projectPartDrawingId"></param>
        /// <returns></returns>
        public ProjectPartDrawing GetProjectPartDrawing(Guid projectPartDrawingId)
        {
            var partDrawing = new ProjectPartDrawing();

            try
            {
                partDrawing = _db.ProjectPartDrawing.FirstOrDefault(x => x.ProjectPartDrawingId == projectPartDrawingId);
            }
            catch (Exception ex)
            {
                logger.ErrorFormat("An error occurred while getting project part drawing. {0}", ex.ToString());
            }

            return(partDrawing);
        }
Пример #10
0
        /// <summary>
        /// convert rfq part view model to project part
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ProjectPart ConvertToDomain(RfqPartViewModel model)
        {
            ProjectPart projectPart = new ProjectPart();

            var _partRepository        = new PartRepository();
            var _projectPartRepository = new ProjectPartRepository();
            var _partStatusRepository  = new PartStatusRepository();

            var active = _partStatusRepository.GetPartStates().FirstOrDefault(x => x.Description == "Active");

            projectPart.ProjectPartId     = model.ProjectPartId;
            projectPart.PartId            = model.PartId;
            projectPart.Number            = model.PartNumber;
            projectPart.AccountCode       = null;
            projectPart.Description       = model.PartDescription;
            projectPart.RevisionNumber    = model.RevisionNumber;
            projectPart.PriceSheetId      = null;
            projectPart.QuoteId           = null;
            projectPart.CustomerId        = model.CustomerId;
            projectPart.CustomerAddressId = null;
            projectPart.FoundryId         = model.FoundryId;
            projectPart.SubFoundryId      = (model.IsNew) ? model.FoundryId : model.SubFoundryId;
            projectPart.HtsNumberId       = null;
            projectPart.MaterialId        = model.MaterialId;
            projectPart.PartStatusId      = (model.IsNew) ? (active != null) ? active.PartStatusId : Guid.Empty : model.PartStatusId;
            projectPart.PartTypeId        = (model.IsNew) ? null : model.PartTypeId;
            projectPart.ShipmentTermId    = null;
            projectPart.PaymentTermId     = null;
            projectPart.SurchargeId       = (model.IsNew) ? null : model.SurchargeId;
            projectPart.SiteId            = null;
            projectPart.DestinationId     = (model.IsNew) ? null : model.DestinationId;
            projectPart.PatternMaterialId = null;
            projectPart.IsRaw             = model.IsRaw;
            projectPart.IsMachined        = model.IsMachined;
            projectPart.Weight            = model.Weight;
            projectPart.Cost               = 0.00m;
            projectPart.Price              = 0.00m;
            projectPart.PalletQuantity     = 0;
            projectPart.AdditionalCost     = 0.00m;
            projectPart.AnnualUsage        = model.AnnualUsage;
            projectPart.FixtureDate        = null;
            projectPart.FixtureCost        = 0.00m;
            projectPart.FixturePrice       = 0.00m;
            projectPart.PatternDate        = null;
            projectPart.PatternCost        = 0.00m;
            projectPart.PatternPrice       = 0.00m;
            projectPart.IsFamilyPattern    = false;
            projectPart.Notes              = null;
            projectPart.CustomerOrderId    = null;
            projectPart.FoundryOrderId     = null;
            projectPart.ToolingDescription = null;

            if (!string.IsNullOrEmpty(model.RevisionNumber) && model.RevisionNumber != "N/A")
            {
                projectPart.ProjectPartDrawings = new List <ProjectPartDrawing>();

                ProjectPartDrawing projectPartDrawing = new ProjectPartDrawing();

                if (model.Drawing != null)
                {
                    projectPartDrawing.ProjectPartId  = model.ProjectPartId;
                    projectPartDrawing.RevisionNumber = model.Drawing.RevisionNumber;
                    projectPartDrawing.Type           = model.Drawing.Type;
                    projectPartDrawing.Length         = model.Drawing.Length;
                    projectPartDrawing.Content        = model.Drawing.Content;
                    projectPartDrawing.IsLatest       = model.Drawing.IsLatest;
                    projectPartDrawing.IsMachined     = model.Drawing.IsMachined;
                    projectPartDrawing.IsRaw          = model.Drawing.IsRaw;
                    projectPartDrawing.IsActive       = model.Drawing.IsActive;
                }
                else
                {
                    if (model.PartId != null)
                    {
                        var drawing = _partRepository.GetPartDrawings(model.PartId ?? Guid.Empty).FirstOrDefault(x => x.RevisionNumber == model.RevisionNumber);
                        projectPartDrawing.ProjectPartId = model.ProjectPartId;
                        if (drawing != null)
                        {
                            projectPartDrawing.RevisionNumber = drawing.RevisionNumber;
                            projectPartDrawing.Type           = drawing.Type;
                            projectPartDrawing.Length         = drawing.Length;
                            projectPartDrawing.Content        = drawing.Content;
                            projectPartDrawing.IsLatest       = drawing.IsLatest;
                            projectPartDrawing.IsMachined     = drawing.IsMachined;
                            projectPartDrawing.IsRaw          = drawing.IsRaw;
                        }
                        projectPartDrawing.IsActive = true;
                    }
                    else
                    {
                        var drawing = _projectPartRepository.GetProjectPartDrawings(model.ProjectPartId).FirstOrDefault(x => x.RevisionNumber == model.RevisionNumber);
                        projectPartDrawing.ProjectPartId  = model.ProjectPartId;
                        projectPartDrawing.RevisionNumber = drawing.RevisionNumber;
                        projectPartDrawing.Type           = drawing.Type;
                        projectPartDrawing.Length         = drawing.Length;
                        projectPartDrawing.Content        = drawing.Content;
                        projectPartDrawing.IsLatest       = drawing.IsLatest;
                        projectPartDrawing.IsMachined     = drawing.IsMachined;
                        projectPartDrawing.IsRaw          = drawing.IsRaw;
                        projectPartDrawing.IsActive       = true;
                    }
                }

                projectPart.ProjectPartDrawings.Add(projectPartDrawing);
            }

            if (_partRepository != null)
            {
                _partRepository.Dispose();
                _partRepository = null;
            }

            if (_projectPartRepository != null)
            {
                _projectPartRepository.Dispose();
                _projectPartRepository = null;
            }

            if (_partStatusRepository != null)
            {
                _partStatusRepository.Dispose();
                _partStatusRepository = null;
            }

            return(projectPart);
        }