Exemplo n.º 1
0
        public async Task <SystemTab> GetOneAsync(string id)
        {
            SystemTab c = await _entityRepository.GetOneAsync(id);

            c.SystemsDescription = !String.IsNullOrEmpty(c.SystemsDescriptionID) ? _systemsdescriptionRepository.GetOneAsync(c.SystemsDescriptionID).Result : null;
            c.Owner    = !String.IsNullOrEmpty(c.OwnerID) ? _ownerRepository.GetOneAsync(c.OwnerID).Result : null;
            c.Status   = !String.IsNullOrEmpty(c.StatusID) ? _statusRepository.GetOneAsync(c.StatusID).Result : null;
            c.Location = !String.IsNullOrEmpty(c.LocationID) ? _locationRepository.GetOneAsync(c.LocationID).Result : null;
            return(c);
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Delete(string id)
        {
            SystemTab systemTab = await _entityService.GetEntityAsync(id);

            if (systemTab == null)
            {
                return(NotFound());
            }

            Status objStatus = null;

            try
            {
                foreach (var lr in systemTab.LeftComponents)
                {
                    var imteToUpdate = await _componentService.GetEntityAsync(lr);

                    imteToUpdate.imteModule = null;
                    objStatus = _statusService.GetEntityAsyncByDescription("Avail_PTS_Shelf").Result;
                    // objStatus = _statusService.GetEntityAsyncByFieldID("Desc", "Avail_PTS_Shelf").Result;
                    imteToUpdate.StatusID = objStatus != null ? (objStatus).Id : null;
                    await _componentService.EditEntityAsync(imteToUpdate);
                }

                foreach (var lr in systemTab.RightComponents)
                {
                    var imteToUpdate = await _componentService.GetEntityAsync(lr);

                    imteToUpdate.imteModule = null;
                    objStatus = _statusService.GetEntityAsyncByDescription("Avail_PTS_Shelf").Result;
                    // objStatus = _statusService.GetEntityAsyncByFieldID("Desc", "Avail_PTS_Shelf").Result;/
                    imteToUpdate.StatusID = objStatus != null ? (objStatus).Id : null;
                    await _componentService.EditEntityAsync(imteToUpdate);
                }
                await _entityService.DeleteEntityAsync(id);
            }
            catch (Exception ex)
            {
                Console.WriteLine("{0} Error in deleting record", ex.Message);
                _logger.LogWarning("Error in deleting {0} record with id = {1}: " + ex.TargetSite.ToString(), "SystemTab", id);

                return(RedirectToAction("Index"));
            }

            await _entityService.DeleteEntityAsync(id);

            return(RedirectToAction("Index"));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> AddOneAsync([FromBody] SystemTab entity)
        {
            if (entity == null)
            {
                return(BadRequest());
            }

            // no duplicate imte allowed
            var result = await _entityRepository.GetOneAsyncByDescription(entity.imte);

            if (result != null)
            {
                return(BadRequest());
            }

            await _entityRepository.AddOneAsync(entity);

            return(CreatedAtRoute("GetSystemTab", new { controller = "SystemTab", id = entity.Id }, entity));
        }
Exemplo n.º 4
0
        private int ValidateIMTE(String imte)
        {
            // no special characters allowed
            char[] chars        = { '+', '&', '|', '!', '(', ')', '{', '}', '[', ']', '^', '~', '*', '?', ':', '\\', ';', '/', '%', '$' };
            int    indexSpecial = imte.IndexOfAny(chars);

            if (indexSpecial >= 0)
            {
                return((int)ErrorCodes.SpecialCharacters);
            }

            // get the portion before the _
            Regex r = new Regex(@"^(?<imtenew>[A-Za-z0-9]+)_?.*$", RegexOptions.None, TimeSpan.FromMilliseconds(200));
            Match m = r.Match(imte);

            if (!m.Success)
            {
                return((int)ErrorCodes.InvalidFormat);
            }

            string[] suffixesIMTE = { String.Empty, "_Yellow", "_Blue", "_Left", "_Right", "_L", "_R" };
            int      cnt          = suffixesIMTE.Count();

            for (int i = 0; i < cnt; i++)
            {
                string    imteToCreate   = imte + suffixesIMTE[i];
                SystemTab systabToCreate = _entityService.GetEntityAsyncByDescription(imteToCreate).Result;
                if (systabToCreate != null)
                {
                    return((int)ErrorCodes.DuplicateIMTESystem);
                }
                else
                {
                    Component compToCreate = _componentService.GetEntityAsyncByDescription(imteToCreate).Result;
                    if (compToCreate != null)
                    {
                        return((int)ErrorCodes.DuplicateIMTEComponent);
                    }
                }
            }

            return((int)ErrorCodes.Valid);
        }
Exemplo n.º 5
0
        public async Task <IEnumerable <EquipmentActivityDTO> > LoadActivities(string descId)
        {
            List <EquipmentActivity> eqactRecords = await _equipmentactivityService.GetSelectedEntitiesAsync("EquipmentActivityID", descId);

            List <EquipmentActivityDTO> eadtoRecords = new List <EquipmentActivityDTO>();

            Fill <EquipmentActivity, EquipmentActivityDTO>(eqactRecords, eadtoRecords);

            foreach (EquipmentActivityDTO ea in eadtoRecords)
            {
                Deployment d = !String.IsNullOrEmpty(ea.DeploymentID) ? _deploymentService.GetEntityAsyncByFieldID("DeploymentID", ea.DeploymentID, "Deployment").Result : null;
                //Deployment d = !String.IsNullOrEmpty(ea.DeploymentID) ? _deploymentService.GetEntityAsync(ea.DeploymentID).Result : null;
                SystemTab st = d != null?_systemtabService.GetEntityAsync(d.SystemTabID).Result : null;

                ea.DeploymentDate = d.DeploymentDate;
                ea.SystemID       = st.imte;
            }

            var items = eadtoRecords
                        .OrderBy(x => x.imte)
                        .ToList();

            return(items);
        }
Exemplo n.º 6
0
 public async Task <ReplaceOneResult> Put([FromBody] SystemTab entity)
 // public async Task<bool> Put([FromBody]SystemTab entity)
 {
     return(await _entityRepository.SaveOneAsync(entity));
 }
Exemplo n.º 7
0
        // GET: Systems/Delete/5
        public async Task <ActionResult> Delete(string id, bool?concurrencyError)
        {
            if (id == null)
            {
                return(BadRequest());
            }

            SystemTab systemTab = await _entityService.GetEntityAsync(id);

            if (systemTab == null)
            {
                return(NotFound());
            }

            List <Component> leftComponents = new List <Component>();

            if (systemTab.LeftComponents != null)
            {
                leftComponents = PopulateLeftRightComponents(systemTab.LeftComponents).Result;
            }

            List <Component> rightComponents = new List <Component>();

            if (systemTab.RightComponents != null)
            {
                rightComponents = PopulateLeftRightComponents(systemTab.RightComponents).Result;
            }

            var countLeft  = systemTab.LeftComponents != null ? systemTab.LeftComponents.Count : 0;
            var countRight = systemTab.RightComponents != null ? systemTab.RightComponents.Count : 0;

            if (countLeft > countRight)
            {
                int diff = countLeft - countRight;
                for (int i = 0; i < diff; i++)
                {
                    Component cRec = new Component();
                    cRec.Description      = new Description();
                    cRec.Description.Desc = null;
                    rightComponents.Add(cRec);
                }
                ;
            }
            else
            if (countLeft < countRight)
            {
                int diff = countRight - countLeft;
                for (int i = 0; i < diff; i++)
                {
                    Component cRec = new Component();
                    cRec.Description      = new Description();
                    cRec.Description.Desc = null;
                    leftComponents.Add(cRec);
                }
                ;
            }
            ;

            ViewBag.leftComponents  = leftComponents;
            ViewBag.rightComponents = rightComponents;

            return(View(systemTab));
        }
Exemplo n.º 8
0
        public async Task <ActionResult> Edit(string id,
                                              [Bind("Id, imte, serialnumber, SystemsDescriptionID, OwnerID, FixtureCode, ModuleCode, Notes, LeftComponents, RightComponents")]
                                              SystemTab systemTab, string[] selectedIMTEs, string typeSubmit)
        {
            string[] fieldsToBind = new string[] { "Id", "imte", "serialnumber", "SystemsDescriptionID", "OwnerID", "FixtureCode", "ModuleCode", "Notes", "LeftComponents", "RightComponents" };

            if (id == null)
            {
                return(BadRequest());
            }

            var recordToUpdate = await _entityService.GetEntityAsync(id);

            if (recordToUpdate == null)
            {
                return(NotFound());
            }

            // Nullify all previous components
            List <string> selectedIMTEsLeft  = new List <string>();
            List <string> selectedIMTEsRight = new List <string>();

            foreach (String s in selectedIMTEs)
            {
                if (s.Substring(0, 1) == "0")
                {
                    selectedIMTEsLeft.Add(s);
                }
                else
                {
                    selectedIMTEsRight.Add(s);
                }
            }

            if (recordToUpdate.LeftComponents != null)
            {
                foreach (String s in recordToUpdate.LeftComponents)
                {
                    if (FindImte(s, selectedIMTEsLeft))
                    {
                        continue;
                    }
                    Component comp = await _componentService.GetEntityAsync(s);

                    comp.imteModule = null;
                    await _componentService.EditEntityAsync(comp);
                }
                ;
            }

            if (recordToUpdate.RightComponents != null)
            {
                foreach (String s in recordToUpdate.RightComponents)
                {
                    if (FindImte(s, selectedIMTEsRight))
                    {
                        continue;
                    }
                    Component comp = await _componentService.GetEntityAsync(s);

                    comp.imteModule = null;
                    await _componentService.EditEntityAsync(comp);
                }
                ;
            }

            if (ModelState.IsValid)
            {
                systemTab.Id = id;
                systemTab.SystemsDescription = await _systemsdescriptionService.GetEntityAsync(systemTab.SystemsDescriptionID);

                systemTab.Owner = await _ownerService.GetEntityAsync(systemTab.OwnerID);

                Status objStatus = (typeSubmit == "Deploy") ? _statusService.GetEntityAsyncByDescription("Active_PROD").Result : _statusService.GetEntityAsyncByDescription("Pending").Result;
                // Status objStatus = (typeSubmit == "Deploy") ? _statusService.GetEntityAsyncByFieldID("Desc", "Active_PROD").Result : _statusService.GetEntityAsyncByFieldID("Desc", "Pending").Result;
                systemTab.StatusID = objStatus != null ? (objStatus).Id : null;

                List <string> leftComponents  = new List <string>();
                List <string> rightComponents = new List <string>();

                foreach (var imte in selectedIMTEsLeft)
                {
                    Component recComponent = await _componentService.GetEntityAsync(imte.Substring(1));

                    recComponent.imteModule = systemTab.imte;
                    recComponent.StatusID   = systemTab.StatusID;
                    leftComponents.Add(imte.Substring(1));

                    await _componentService.EditEntityAsync(recComponent);
                }

                foreach (var imte in selectedIMTEsRight)
                {
                    Component recComponent = await _componentService.GetEntityAsync(imte.Substring(1));

                    recComponent.imteModule = systemTab.imte;
                    recComponent.StatusID   = systemTab.StatusID;
                    rightComponents.Add(imte.Substring(1));

                    await _componentService.EditEntityAsync(recComponent);
                }

                systemTab.LeftComponents  = leftComponents;
                systemTab.RightComponents = rightComponents;
                systemTab.CreatedAtUtc    = DateTime.Now;

                await _entityService.EditEntityAsync(systemTab);

                return(RedirectToAction("Index"));
            }

            return(View(recordToUpdate));
        }
Exemplo n.º 9
0
        // GET: Systems/Edit/5
        public async Task <ActionResult> Edit(string Id)
        {
            if (Id == null)
            {
                return(NotFound());
            }

            SystemTab systemTab = await _entityService.GetEntityAsync(Id);

            if (systemTab == null)
            {
                return(NotFound());
            }

            // http://stackoverflow.com/questions/668589/how-can-i-add-an-item-to-a-selectlist-in-asp-net-mvc
            List <SystemsDescription> descRecords = await _systemsdescriptionService.GetEntitiesAsync();

            List <SelectListItem> sl = new SelectList(descRecords.OrderBy(x => x.Desc), "Id", "Desc", systemTab.SystemsDescriptionID).ToList();

            if (systemTab.SystemsDescriptionID == null)
            {
                sl.Insert(0, new SelectListItem {
                    Value = "0", Text = "Please Select", Selected = true
                });
            }
            ViewBag.SystemsDescriptionID = sl;

            List <Owner> ownerRecords = await _ownerService.GetEntitiesAsync();

            sl = new SelectList(ownerRecords.OrderBy(x => x.Desc), "Id", "Desc", systemTab.OwnerID).ToList();
            if (systemTab.OwnerID == null)
            {
                sl.Insert(0, new SelectListItem {
                    Value = "0", Text = "Please Select", Selected = true
                });
            }
            ViewBag.OwnerID = sl;

            List <Location> locationRecords = await _locationService.GetEntitiesAsync();

            sl = new SelectList(locationRecords.OrderBy(x => x.Desc), "Id", "Desc", systemTab.LocationID).ToList();
            if (systemTab.LocationID == null)
            {
                sl.Insert(0, new SelectListItem {
                    Value = "0", Text = "Please Select", Selected = true
                });
            }
            ViewBag.LocationID = sl;

            //ViewBag.LocationID = new SelectList(locationRecords.OrderBy(x => x.Desc), "Id", "Desc", systemTab.LocationID);

            // select only components that are not yet commissioned
            List <Component> compRecords = await _componentService.GetEntitiesAsync();

            var items = compRecords
                        .OrderBy(x => x.Description.Desc)
                        .Where(x => x.imteModule == null);
            // .Where(x => String.IsNullOrEmpty(x.imteModule));

            //ViewBag.ComponentID = new SelectList(compRecords.OrderBy(x => x.Description.Desc).Where(x => x.imteModule == systemTab.ModuleCode || String.IsNullOrEmpty(x.imteModule) ), "Id", "DescTag");

            // create lookup table with key = Description and value = IEnumerable<Component>
            ILookup <string, Component> lookup = items
                                                 .ToLookup(p => p.Description.Desc.Trim() + (!String.IsNullOrEmpty(p.Description.Tag) ? " (" + p.Description.Tag + ")" : null),
                                                           p => p); // will be used to create a select list of p.IMTE + " " + p.MaintenanceDateTime);

            ViewBag.LookUp = lookup;

            // from the lookup table: create a select list of description + tag only
            var listDesc = new List <SelectListItem>();

            foreach (IGrouping <string, Component> g in lookup)
            {
                listDesc.Add
                (
                    new SelectListItem {
                    Value = g.Key, Text = g.Key
                }
                );
            }
            ViewBag.ComponentDescID = new SelectList(listDesc, "Value", "Text");

            ViewBag.leftComponents  = null;
            ViewBag.rightComponents = null;

            List <string> leftIMTEs  = systemTab.LeftComponents;
            List <string> rightIMTEs = systemTab.RightComponents;

            List <Component> leftComponents  = new List <Component>();
            List <Component> rightComponents = new List <Component>();

            foreach (String c in leftIMTEs)
            {
                var imteToAdd = await _componentService.GetEntityAsync(c);

                leftComponents.Add(imteToAdd);
            }

            foreach (String c in rightIMTEs)
            {
                var imteToAdd = await _componentService.GetEntityAsync(c);

                rightComponents.Add(imteToAdd);
            }

            /*
             * foreach (var lr in leftIMTEs.Zip(rightIMTEs, Tuple.Create))
             * {
             *  var imteToAdd = await _componentService.GetEntityAsync(lr.Item1);
             *  leftComponents.Add(imteToAdd);
             *
             *  imteToAdd = await _componentService.GetEntityAsync(lr.Item2);
             *  rightComponents.Add(imteToAdd);
             * }
             */

            ViewBag.leftComponents  = leftComponents;
            ViewBag.rightComponents = rightComponents;

            return(View(systemTab));
        }
Exemplo n.º 10
0
        public async Task <ActionResult> Create([Bind("imte, serialnumber, SystemsDescriptionID, OwnerID, LocationID, Notes")]
                                                SystemTab systemTab, string[] selectedIMTEs, string typeSubmit)
        {
            // check if imte valid
            int resValidateIMTE = ValidateIMTE(systemTab.imte);

            // valid
            if (resValidateIMTE == (int)ErrorCodes.Valid)
            {
                List <string> leftComponents  = new List <string>();
                List <string> rightComponents = new List <string>();

                Status statusRecord = (typeSubmit == "Deploy") ? _statusService.GetEntityAsyncByDescription("Active_PROD").Result : _statusService.GetEntityAsyncByDescription("Pending").Result;
                // Status statusRecord = (typeSubmit == "Deploy") ? _statusService.GetEntityAsyncByFieldID("Active_PROD").Result : _statusService.GetEntityAsyncByFieldID("Pending").Result;
                string statusID = statusRecord != null ? statusRecord.Id : null;

                foreach (var imte in selectedIMTEs)
                {
                    Component recComponent = await _componentService.GetEntityAsync(imte.Substring(1));

                    recComponent.imteModule = systemTab.imte;
                    recComponent.Status     = statusRecord;
                    recComponent.StatusID   = statusID;

                    if (imte.Substring(0, 1) == "0")
                    {
                        leftComponents.Add(imte.Substring(1));
                    }
                    else
                    {
                        rightComponents.Add(imte.Substring(1));
                    }
                    await _componentService.EditEntityAsync(recComponent);
                }

                if (ModelState.IsValid)
                {
                    systemTab.serialnumber       = !String.IsNullOrEmpty(systemTab.serialnumber) ? systemTab.serialnumber : String.Empty;
                    systemTab.SystemsDescription = !String.IsNullOrEmpty(systemTab.SystemsDescriptionID) ? await _systemsdescriptionService.GetEntityAsync(systemTab.SystemsDescriptionID): null;

                    systemTab.Owner = !String.IsNullOrEmpty(systemTab.OwnerID) ? await _ownerService.GetEntityAsync(systemTab.OwnerID):null;

                    systemTab.Location = !String.IsNullOrEmpty(systemTab.LocationID) ? await _locationService.GetEntityAsync(systemTab.LocationID) : null;

                    systemTab.ReferenceNo     = !String.IsNullOrEmpty(systemTab.ReferenceNo) ? systemTab.ReferenceNo : String.Empty;
                    systemTab.Status          = statusRecord;
                    systemTab.StatusID        = statusID;
                    systemTab.LeftComponents  = leftComponents;
                    systemTab.RightComponents = rightComponents;
                    systemTab.DeploymentDate  = (typeSubmit == "Deploy") ? DateTime.Now : (DateTime?)null;
                    systemTab.CreatedAtUtc    = DateTime.Now;
                    await _entityService.PostEntityAsync(systemTab);

                    return(RedirectToAction("Index"));
                }
            }

            // invalid
            switch (resValidateIMTE)
            {
            case (int)ErrorCodes.SpecialCharacters:
                ModelState.AddModelError("imte", "No special characters allowed");
                break;

            case (int)ErrorCodes.InvalidFormat:
                ModelState.AddModelError("imte", "IMTE formatted incorrectly");
                break;

            case (int)ErrorCodes.DuplicateIMTESystem:
                ModelState.AddModelError("imte", "Duplicate imte found in System Table");
                break;

            case (int)ErrorCodes.DuplicateIMTEComponent:
                ModelState.AddModelError("imte", "Duplicate imte found in Component Table");
                break;

            default:
                break;
            }

            CreateCommon();

            if (selectedIMTEs != null)
            {
                List <Component> leftComponents  = new List <Component>();
                List <Component> rightComponents = new List <Component>();

                foreach (var imte in selectedIMTEs)
                {
                    var imteToAdd = await _componentService.GetEntityAsync(imte.Substring(1));

                    if (imte.Substring(0, 1) == "0")
                    {
                        leftComponents.Add(imteToAdd);
                    }
                    else
                    {
                        rightComponents.Add(imteToAdd);
                    }

                    // remove component already selected from the dropdownlist
                    //items = items.Where(x => x.Id != imteToAdd.Id);

                    //items.Remove(items.Where(c => c.Value == Convert.ToString(imteToAdd.ID)).Single());
                }
                ViewBag.leftComponents  = leftComponents;
                ViewBag.rightComponents = rightComponents;
            }
            ;

            return(View(systemTab));                    //return RedirectToAction("Create", systemTab);
        }