Пример #1
0
 public void Update()
 {
     while (AddComponents.Count > 0)
     {
         AllComponents.Add(AddComponents[0]);
         AddComponents.RemoveAt(0);
     }
     foreach (var item in AllComponents)
     {
         if (item.IsDisposed)
         {
             RemoveComponents.Add(item);
             continue;
         }
         item.Update();
     }
     if (RemoveComponents.Count > 0)
     {
         foreach (var item in RemoveComponents)
         {
             AllComponents.Remove(item);
         }
         RemoveComponents.Clear();
     }
 }
        public ResponseMessage AddComponents(AddComponents servicedto)
        {
            ResponseMessage responseMessage = new ResponseMessage();

            responseMessage = _repository.AddComponents(servicedto);
            if (responseMessage != null)
            {
                return(responseMessage);
            }
            else
            {
                return(new ResponseMessage()
                {
                    Message = "",
                });
            }
        }
 public IActionResult Addcomponents(AddComponents request)
 {
     try
     {
         var projectStructure = _componentService.AddComponents(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"
         }));
     }
 }
Пример #4
0
    public static void CreateWindow()
    {
        AddComponents window = GetWindow <AddComponents>();

        window.Show();
    }
        public ResponseMessage AddComponents(AddComponents request)
        {
            ResponseMessage response = new ResponseMessage();

            response.Message = "Components added succusfully";
            List <dispatchedStrucCount> result = new List <dispatchedStrucCount>();
            int count      = _context.Component.Where(s => s.ProjStructId == request.ProjStructId).Count();
            int Quantity   = request.Components.Where(x => x.CompId == null).Count();
            int excedCout  = count + Quantity;
            int totalcount = _context.ProjectStructure.Single(s => s.Id == request.ProjStructId).ComponentsCount ?? 0;

            if (totalcount < excedCout)
            {
                throw new ValueNotFoundException("Dispatch Components should match the required quantity.");
            }

            try {
                //	using (var transaction = _context.Database.BeginTransaction ())
                try {
                    var isUpdate                      = false;
                    var projectStructureID            = 0;
                    ProjectStructure projectStructure = _context.ProjectStructure.Where(x => x.Id == request.ProjStructId && x.IsDelete == false).FirstOrDefault();
                    int compCount                     = _context.Component.Where(x => x.ProjStructId == request.ProjStructId).Count();
                    int payLoadeCompCount             = request.Components.Where(x => x.CompId == null).Count();
                    int excedcout                     = payLoadeCompCount + compCount;
                    if (projectStructure.ComponentsCount < excedcout)
                    {
                        throw new ValueNotFoundException("Component limit exceed");
                    }
                    if (projectStructure == null)
                    {
                        throw new ValueNotFoundException("Project Structure not yet assigned");
                    }
                    projectStructureID = projectStructure.Id;
                    if (request.Components?.Count > 0)
                    {
                        List <Component>        componentls     = new List <Component> ();
                        List <ComponentHistory> componentHistls = new List <ComponentHistory> ();
                        foreach (var comp in request.Components)
                        {
                            ComponentType compTypeDB = _context.ComponentType.Where(x => x.Name == comp.CompTypeName && x.IsDelete == false).FirstOrDefault();
                            if (compTypeDB == null)
                            {
                                throw new ValueNotFoundException("Component Type Name doesn't exist");
                            }
                        }
                        foreach (var comp in request.Components)
                        {
                            var           compdb     = _context.Component.Where(x => x.CompId == comp.CompId && x.IsDelete == false).FirstOrDefault();
                            ComponentType compTypeDB = _context.ComponentType.Where(x => x.Name == comp.CompTypeName && x.IsDelete == false).FirstOrDefault();

                            if (compTypeDB == null)
                            {
                                throw new ValueNotFoundException("Component Type Name doesn't exist");
                            }
                            if (compdb != null)
                            {
                                compdb = ConstructComponent(projectStructureID, comp, compdb, compTypeDB);
                                _context.SaveChanges();
                            }
                            else
                            {
                                Component component = null;
                                comp.CompStatus = "O";
                                component       = ConstructComponent(projectStructureID, comp, component, compTypeDB);
                                _context.Component.Add(component);
                                _context.SaveChanges();
                            }
                        }
                        // projectStructure.ComponentsCount = request.Components.Count ();
                        _context.SaveChanges();
                    }
                    return(response);
                } catch (Exception ex) {
                    //	transaction.Rollback ();
                    throw ex;
                }
            } catch (Exception ex) {
                throw ex;
            }
        }