コード例 #1
0
        public int UpsertProjectStructure(AssignStructureComponentDetails request)
        {
            ResponseMessage response = new ResponseMessage();

            response.Message = "Structure-compoennet assigned succusfully";
            // if (request?.ProjectStructureDetail == null)
            //  throw new ValueNotFoundException ("ProjectStructureDetail Request cannot be empty.");

            try {
                using (var transaction = _context.Database.BeginTransaction()) {
                    try {
                        var isUpdate           = false;
                        var projectStructureID = 0;
                        var projectStructure   = _context.ProjectStructure.Where(x => x.StructureId == request.StructureId && x.ProjectId == request.ProjectId && x.IsDelete == false).FirstOrDefault();
                        if (request.ProjectStructureId != null)
                        {
                            projectStructure = _context.ProjectStructure.Where(x => x.Id == request.ProjectStructureId && x.IsDelete == false).FirstOrDefault();
                        }

                        if (projectStructure != null)
                        {
                            projectStructure   = ConstructProjectStructure(request, projectStructure);
                            projectStructureID = projectStructure.Id;
                            isUpdate           = true;
                            _context.SaveChanges();
                        }
                        else
                        {
                            ProjectStructure projStructdb = null;
                            projStructdb = ConstructProjectStructure(request, projStructdb);
                            projStructdb.StructureStatus = Util.GetDescription(commonEnum.StructureStatus.AVAILABLE).ToString();
                            projStructdb.CurrentStatus   = Util.GetDescription(commonEnum.StructureInternalStatus.NEW).ToString();
                            _context.ProjectStructure.Add(projStructdb);
                            _context.SaveChanges();
                            projectStructureID = projStructdb.Id;
                        }
                        transaction.Commit();
                        return(projectStructureID);
                    } catch (Exception ex) {
                        transaction.Rollback();
                        throw ex;
                    }
                }
            } catch (Exception ex) {
                throw ex;
            }
        }
        public IActionResult AssignStructurecomponent([FromForm] AssignStructureComponentDetails request)
        {
            try
            {
                if (request.uploadDocs != null)
                {
                    if (request.uploadDocs.Length > 5)
                    {
                        throw new ValueNotFoundException("Document count should not greater than 5");
                    }
                    foreach (IFormFile file in request.uploadDocs)
                    {
                        if (constantVal.AllowedDocFileTypes.Where(x => x.Contains(file.ContentType)).Count() == 0)
                        {
                            throw new ValueNotFoundException(string.Format("File Type {0} is not allowed", file.ContentType));
                        }
                    }
                    if (request.uploadDocs.Select(x => x.Length).Sum() > 50000000)
                    {
                        throw new ValueNotFoundException(" File size exceeded limit");
                    }
                }

                var projectStructure = _assignService.UpsertAssignStructureComponent(request);
                return(Ok(projectStructure));
            }
            catch (ValueNotFoundException e)
            {
                Util.LogError(e);
                return(StatusCode(StatusCodes.Status422UnprocessableEntity, new ErrorClass()
                {
                    code = StatusCodes.Status422UnprocessableEntity.ToString(), message = e.Message
                }));
            }
            catch (Exception e)
            {
                Util.LogError(e);
                return(StatusCode(StatusCodes.Status500InternalServerError, new ErrorClass()
                {
                    code = StatusCodes.Status500InternalServerError.ToString(), message = "Something went wrong"
                }));
            }
        }
コード例 #3
0
        private ProjectStructure ConstructProjectStructure(AssignStructureComponentDetails request, ProjectStructure projStruct)
        {
            int    structCount = _context.ProjectStructure.Count() + 1;
            string structId    = constantVal.StructureIdPrefix + structCount.ToString().PadLeft(6, '0');

            if (projStruct == null)
            {
                projStruct           = new ProjectStructure();
                projStruct.CreatedAt = DateTime.Now;
            }
            projStruct.ProjectId              = request.ProjectId;
            projStruct.StructureId            = request.StructureId;
            projStruct.StructCode             = request.StructureCode;
            projStruct.IsDelete               = false;
            projStruct.DrawingNo              = request.DrawingNo;
            projStruct.UpdatedAt              = DateTime.Now;
            projStruct.EstimatedWeight        = Convert.ToDecimal(request.EstimatedWeight);
            projStruct.StructCode             = structId;
            projStruct.ComponentsCount        = request.CompCount;
            projStruct.StructureAttributesVal = request.StructureAttributes;
            return(projStruct);
        }
コード例 #4
0
        public ResponseMessage UpsertAssignStructureComponent(AssignStructureComponentDetails servicedto)
        {
            ResponseMessage response = new ResponseMessage();

            response.Message = "Structure-compoenent assigned succusfully";
            int projStructId = _repository.UpsertProjectStructure(servicedto);

            if (servicedto.uploadDocs != null)
            {
                foreach (IFormFile file in servicedto.uploadDocs)
                {
                    Upload_Docs layerDoc = new Upload_Docs();
                    layerDoc.fileName   = file.FileName;
                    layerDoc.filepath   = UploadedFile(file);
                    layerDoc.uploadType = "Docs";
                    layerDoc.fileType   = Path.GetExtension(file.FileName);
                    this._repository.StructureDocsUpload(layerDoc, projStructId);
                    //  _gridRepo.LayerDocsUpload(layerDoc, layerId);
                }
            }
            RemoveStructureDocs(servicedto.remove_docs_filename);

            return(response);
        }