コード例 #1
0
        public ResponseMessage OSAssignVendor(OSDispatchReqSubCont oSDispatchReqSubCont)
        {
            ResponseMessage responseMessage = new ResponseMessage();

            responseMessage = _dispatchReqSubConRepository.OSAssignVendor(oSDispatchReqSubCont);
            return(responseMessage);
        }
コード例 #2
0
 public IActionResult OSAssignVendor(OSDispatchReqSubCont oSDispatchReqSubCont)
 {
     try
     {
         var response = _dispatchService.OSAssignVendor(oSDispatchReqSubCont);
         return(StatusCode(StatusCodes.Status201Created, (new { message = response.Message, code = 201 })));
     }
     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
        public ResponseMessage OSAssignVendor(OSDispatchReqSubCont oSDispatchReqSubCont)
        {
            try
            {
                ResponseMessage     responseMessage   = new ResponseMessage();
                string[]            strAllowedService = { commonEnum.ServiceType.Fabrication.ToString(), commonEnum.ServiceType.OutSourcing.ToString(), commonEnum.ServiceType.Reuse.ToString() };
                DispatchRequirement dispReq           = _context.DispatchRequirement.Include(c => c.Servicetype).Where(x => x.DispatchNo == oSDispatchReqSubCont.DispatchNo).FirstOrDefault();
                if (dispReq.StatusInternal != Util.GetDescription(commonEnum.SiteDispatchSatus.NEW).ToString() && !strAllowedService.Contains(dispReq.Servicetype.Name))
                {
                    throw new ValueNotFoundException("Assign Vendor not allowed");
                }
                DispatchreqSubcont dispatchreqSubcont = new DispatchreqSubcont();
                dispatchreqSubcont.ServicetypeId = oSDispatchReqSubCont.ServiceType;
                dispatchreqSubcont.DispatchNo    = oSDispatchReqSubCont.DispatchNo;
                dispatchreqSubcont.DispreqId     = oSDispatchReqSubCont.DispreqId;
                //  dispatchreqSubcont.
                dispatchreqSubcont.CreatedAt      = DateTime.Now;
                dispatchreqSubcont.CreatedBy      = 1; //TODO
                dispatchreqSubcont.Status         = "New";
                dispatchreqSubcont.StatusInternal = "New";
                if (oSDispatchReqSubCont.ServiceType > 0)
                {
                    dispatchreqSubcont.ServicetypeId = oSDispatchReqSubCont.ServiceType;
                }
                else
                {
                    dispatchreqSubcont.ServicetypeId = 2;
                }


                //Add the dispatch subcont structure
                if (oSDispatchReqSubCont.VendorStructures.Any())
                {
                    var groupbyVendor = oSDispatchReqSubCont.VendorStructures.GroupBy(c => c.SubContId);
                    foreach (var group in groupbyVendor)
                    {
                        dispatchreqSubcont.SubconId = group.Key;
                        dispatchreqSubcont.Quantity = group.Count();
                        _context.DispatchreqSubcont.Add(dispatchreqSubcont);
                        _context.SaveChanges();
                        foreach (var item in group)
                        {
                            DispReqStructure drsDB = _context.DispReqStructure.Where(x => x.ProjStructId == item.ProjStructureId && x.DispreqId == oSDispatchReqSubCont.DispreqId).FirstOrDefault();
                            if (drsDB == null)
                            {
                                throw new ValueNotFoundException("Dispatch Requirement ID & Project Struct  ID doesn't exists");
                            }

                            DispSubcontStructure dispSubcontStructure = new DispSubcontStructure();
                            dispSubcontStructure.ProjStructId     = item.ProjStructureId;
                            dispSubcontStructure.DispreqsubcontId = dispatchreqSubcont.Id;
                            dispSubcontStructure.DispStructureId  = drsDB.Id;
                            _context.DispSubcontStructure.Add(dispSubcontStructure);
                            _context.SaveChanges();
                        }
                    }
                }
                dispReq.StatusInternal = Util.GetDescription(commonEnum.SiteDispatchSatus.PROCAPPROVED).ToString();
                dispReq.Status         = Util.GetDescription(commonEnum.SiteDispatchSatus.PROCAPPROVED).ToString();
                _context.SaveChanges();
                responseMessage.Message = "Vendor assigned successfully";
                return(responseMessage);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }