Example #1
0
        public async Task<bool> ResolveAssetRef(JsonPatchDocument<JobTask> taskPatch, JobTask jobTask)
        {
            var assetRefReplaceOp = taskPatch.Operations.FirstOrDefault(x => x.op == "replace" && x.path == "/AssetRef");
            if (!(assetRefReplaceOp?.value is string)) return false;
            // INFO: Now we need to actually fetch the asset and get shit done
            if (jobTask.State == JobTaskState.COMPLETED)
                throw new InvalidOperationException($"Updating AssetRef of JobTask {jobTask.id} is not suppported as the task is in {jobTask.State} state");

            var asset = await _accountManager.FindAsByIdAsync<Data.Entity.Identity.Asset>(assetRefReplaceOp.value.ToString());
            if (asset == null) return false;
            var assetModel = new AssetModel(asset);
            assetRefReplaceOp.path = "/Asset";
            assetRefReplaceOp.value = assetModel;
            return true;
        }
        public async Task <ActionResult> CreatePost(AssetModel asset)
        {
            try
            {
                bool edit = false;
                if (asset == null)
                {
                    return(HttpNotFound());
                }
                Asset dbAsset = null;
                if (asset.Id == 0)
                {
                    dbAsset = new Asset();
                }
                else
                {
                    edit    = true;
                    dbAsset = await db.Assets.FindAsync(asset.Id).ConfigureAwait(true);
                }
                dbAsset.Name    = asset.Name;
                dbAsset.AssetId = asset.AssetId;
                dbAsset.Status  = (int)asset.Status;
                dbAsset.TagId   = asset.TagId;
                dbAsset.Details = asset.Details;
                if (asset.ExpireDate != DateTime.MinValue)
                {
                    dbAsset.ExpireDate = asset.ExpireDate;
                }
                dbAsset.SerialNumber = asset.SerialNumber;
                if (asset.PurchaseDate != DateTime.MinValue)
                {
                    dbAsset.PurchaseDate = asset.PurchaseDate;
                }
                dbAsset.Cost = asset.Cost;
                if (asset.SubAsset)
                {
                    dbAsset.MultibleSubSelected = asset.MultibleSubSelected;
                    dbAsset.SubAsset            = true;
                    if (dbAsset.SubAssets != null && dbAsset.SubAssets.Any())
                    {
                        var subList = new List <SubAsset>();
                        foreach (var sub in dbAsset.SubAssets)
                        {
                            subList.Add(sub);
                        }
                        foreach (var item in subList)
                        {
                            db.SubAssets.Remove(item);
                        }
                        subList.Clear();
                    }
                    if (!string.IsNullOrEmpty(asset.SubAssetListName0))
                    {
                        dbAsset.SubAssets = new Collection <SubAsset>();
                        dbAsset.SubAssets.Add(new SubAsset()
                        {
                            Status      = 1,
                            CreatedDate = DateTime.Now,
                            Name        = asset.SubAssetListName0,
                            TagId       = asset.SubAssetListTagId0,
                        });
                    }
                    if (!string.IsNullOrEmpty(asset.SubAssetListName1))
                    {
                        dbAsset.SubAssets.Add(new SubAsset()
                        {
                            Status      = 1,
                            CreatedDate = DateTime.Now,
                            Name        = asset.SubAssetListName1,
                            TagId       = asset.SubAssetListTagId1,
                        });
                    }
                    if (!string.IsNullOrEmpty(asset.SubAssetListName2))
                    {
                        dbAsset.SubAssets.Add(new SubAsset()
                        {
                            Status      = 1,
                            CreatedDate = DateTime.Now,
                            Name        = asset.SubAssetListName2,
                            TagId       = asset.SubAssetListTagId2,
                        });
                    }
                    if (!string.IsNullOrEmpty(asset.SubAssetListName3))
                    {
                        dbAsset.SubAssets.Add(new SubAsset()
                        {
                            Status      = 1,
                            CreatedDate = DateTime.Now,
                            Name        = asset.SubAssetListName3,
                            TagId       = asset.SubAssetListTagId3,
                        });
                    }
                    if (!string.IsNullOrEmpty(asset.SubAssetListName4))
                    {
                        dbAsset.SubAssets.Add(new SubAsset()
                        {
                            Status      = 1,
                            CreatedDate = DateTime.Now,
                            Name        = asset.SubAssetListName4,
                            TagId       = asset.SubAssetListTagId4,
                        });
                    }
                    if (!string.IsNullOrEmpty(asset.SubAssetListName5))
                    {
                        dbAsset.SubAssets.Add(new SubAsset()
                        {
                            Status      = 1,
                            CreatedDate = DateTime.Now,
                            Name        = asset.SubAssetListName5,
                            TagId       = asset.SubAssetListTagId5,
                        });
                    }
                    if (!string.IsNullOrEmpty(asset.SubAssetListName6))
                    {
                        dbAsset.SubAssets.Add(new SubAsset()
                        {
                            Status      = 1,
                            CreatedDate = DateTime.Now,
                            Name        = asset.SubAssetListName6,
                            TagId       = asset.SubAssetListTagId6,
                        });
                    }
                    if (!string.IsNullOrEmpty(asset.SubAssetListName7))
                    {
                        dbAsset.SubAssets.Add(new SubAsset()
                        {
                            Status      = 1,
                            CreatedDate = DateTime.Now,
                            Name        = asset.SubAssetListName7,
                            TagId       = asset.SubAssetListTagId7,
                        });
                    }
                    if (!string.IsNullOrEmpty(asset.SubAssetListName8))
                    {
                        dbAsset.SubAssets.Add(new SubAsset()
                        {
                            Status      = 1,
                            CreatedDate = DateTime.Now,
                            Name        = asset.SubAssetListName8,
                            TagId       = asset.SubAssetListTagId8,
                        });
                    }
                    if (!string.IsNullOrEmpty(asset.SubAssetListName9))
                    {
                        dbAsset.SubAssets.Add(new SubAsset()
                        {
                            Status      = 1,
                            CreatedDate = DateTime.Now,
                            Name        = asset.SubAssetListName9,
                            TagId       = asset.SubAssetListTagId9,
                        });
                    }
                }
                else
                {
                    if (dbAsset.SubAssets != null && dbAsset.SubAssets.Any())
                    {
                        var subList = new List <SubAsset>();
                        foreach (var sub in dbAsset.SubAssets)
                        {
                            subList.Add(sub);
                        }
                        foreach (var item in subList)
                        {
                            db.SubAssets.Remove(item);
                        }
                        subList.Clear();
                    }
                    dbAsset.SubAsset            = false;
                    dbAsset.MultibleSubSelected = false;
                }
                if (!string.IsNullOrEmpty(asset.SiteName))
                {
                    dbAsset.SiteId           = 0;
                    dbAsset.Site             = new Site();
                    dbAsset.Site.City        = asset.SiteCity;
                    dbAsset.Site.Country     = asset.SiteCountry;
                    dbAsset.Site.PostalCode  = asset.SitePostalCode;
                    dbAsset.Site.Name        = asset.SiteName;
                    dbAsset.Site.State       = asset.SiteState;
                    dbAsset.Site.Status      = (int)asset.SiteStatus;
                    dbAsset.Site.Street      = asset.SiteStreet;
                    dbAsset.Site.TagId       = asset.SiteTagId;
                    dbAsset.Site.Detail      = asset.SiteDetail;
                    dbAsset.Site.CreatedDate = DateTime.Now;
                }
                else
                {
                    dbAsset.SiteId = asset.SiteId;
                }
                if (!string.IsNullOrEmpty(asset.TypeName))
                {
                    dbAsset.TypeId          = 0;
                    dbAsset.Type            = new Models.Type();
                    dbAsset.Type.Name       = asset.TypeName;
                    dbAsset.Type.Detail     = asset.TypeDetail;
                    dbAsset.Type.CreateDate = DateTime.Now;
                }
                else
                {
                    dbAsset.TypeId = asset.TypeId;
                }
                if (!string.IsNullOrEmpty(asset.CategoryName))
                {
                    dbAsset.CategoryId           = 0;
                    dbAsset.Category             = new Models.Category();
                    dbAsset.Category.Name        = asset.CategoryName;
                    dbAsset.Category.Detail      = asset.CategoryDetail;
                    dbAsset.Category.CreatedDate = DateTime.Now;
                }
                else
                {
                    dbAsset.CategoryId = asset.CategoryId;
                }
                if (!string.IsNullOrEmpty(asset.DepartmentName))
                {
                    dbAsset.DepartmentId          = 0;
                    dbAsset.Department            = new Models.Department();
                    dbAsset.Department.Name       = asset.DepartmentName;
                    dbAsset.Department.Detail     = asset.DepartmentDetail;
                    dbAsset.Department.CreateDate = DateTime.Now;
                }
                else
                {
                    if (asset.DepartmentId != 0)
                    {
                        dbAsset.DepartmentId = asset.DepartmentId;
                    }
                }


                if (!string.IsNullOrEmpty(asset.LocationName))
                {
                    dbAsset.LocationId           = 0;
                    dbAsset.Location             = new Models.Location();
                    dbAsset.Location.Name        = asset.LocationName;
                    dbAsset.Location.Detail      = asset.LocationName;
                    dbAsset.Location.CreatedDate = DateTime.Now;
                    if (string.IsNullOrEmpty(asset.SiteName))
                    {
                        dbAsset.Location.SiteId = asset.SiteId;
                    }
                    else
                    {
                        dbAsset.Location.Site = dbAsset.Site;
                    }
                    if (!edit)
                    {
                        dbAsset.Location1 = dbAsset.Location;
                    }
                }
                else
                {
                    dbAsset.LocationId = asset.LocationId;
                    if (!edit)
                    {
                        dbAsset.CurrentLocation = asset.LocationId;
                    }
                }

                if (asset.ImageFile != null)
                {
                    var imagePath     = Path.Combine(Server.MapPath("~/Content"), Session["USERNAME"].ToString());
                    var imageName     = $"{Guid.NewGuid()}_{asset.ImageFile.FileName}";
                    var dbImagePath   = Path.Combine(Session["USERNAME"].ToString(), imageName);
                    var imageFullPath = Path.Combine(imagePath, imageName);
                    if (!Directory.Exists(imagePath))
                    {
                        Directory.CreateDirectory(imagePath);
                    }
                    if (System.IO.File.Exists(imageFullPath))
                    {
                        System.IO.File.Delete(imageFullPath);
                    }
                    asset.ImageFile.SaveAs(imageFullPath);
                    if (edit)
                    {
                        dbAsset.AssetImage = await db.AssetImages.FindAsync(asset.Id).ConfigureAwait(true);

                        if (dbAsset.AssetImage == null)
                        {
                            dbAsset.AssetImage             = new AssetImage();
                            dbAsset.AssetImage.CreatedDate = DateTime.Now;
                        }
                    }
                    else
                    {
                        dbAsset.AssetImage             = new AssetImage();
                        dbAsset.AssetImage.CreatedDate = DateTime.Now;
                    }
                    dbAsset.AssetImage.Name   = asset.ImageFile.FileName;
                    dbAsset.AssetImage.Size   = (int)asset.ImageFile.InputStream.Length;
                    dbAsset.AssetImage.Path   = dbImagePath;
                    dbAsset.AssetImage.Status = 1;
                }
                if (edit)
                {
                    db.Entry(dbAsset).State = EntityState.Modified;
                }
                else
                {
                    dbAsset.CreatedDate = DateTime.Now;
                    db.Assets.Add(dbAsset);
                }
                await db.SaveChangesAsync();

                ModelState.Clear();
                return(RedirectToAction("Index"));
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                          ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw;
            }
        }
        // GET: Assets/Details/5
        public async Task <ActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Asset asset = await db.Assets.FindAsync(id);

            if (asset == null)
            {
                return(HttpNotFound());
            }
            var model = new AssetModel();

            model.AssetImage = new AssetImage();
            if (asset.AssetImage != null)
            {
                model.AssetImage.Path = Url.Content("~/Content/" + asset.AssetImage.Path.Replace("\\", "/"));
            }
            else
            {
                model.AssetImage.Path = Url.Content("~/images/asset.png");
            }
            model.Id           = asset.Id;
            model.Name         = asset.Name;
            model.CategoryId   = asset.CategoryId;
            model.Details      = asset.Details;
            model.TypeId       = asset.TypeId;
            model.SiteId       = asset.SiteId;
            model.AssetId      = asset.AssetId;
            model.LocationId   = asset.LocationId;
            model.DepartmentId = asset.DepartmentId.HasValue ? asset.DepartmentId.Value : 0;
            if (asset.ExpireDate.HasValue)
            {
                model.ExpireDate = asset.ExpireDate.Value;
            }
            if (asset.PurchaseDate.HasValue)
            {
                model.PurchaseDate = asset.PurchaseDate.Value;
            }
            if (asset.SubAsset)
            {
                model.SubAsset = true;
                if (asset.MultibleSubSelected.HasValue)
                {
                    model.MultibleSubSelected = asset.MultibleSubSelected.Value;
                }
                if (asset.SubAssets != null && asset.SubAssets.Any())
                {
                    model.SubAssets = new List <SubAsetModel>();
                    foreach (var item in asset.SubAssets)
                    {
                        model.SubAssets.Add(new SubAsetModel()
                        {
                            Name  = item.Name,
                            TagId = item.TagId
                        });
                    }
                }
            }

            if (asset.Cost.HasValue)
            {
                model.Cost = asset.Cost.Value;
            }
            model.SerialNumber = asset.SerialNumber;
            model.TagId        = asset.TagId;
            model.Status       = (AssetStatus)asset.Status;
            return(Json(model, JsonRequestBehavior.AllowGet));
        }
 public CreateAssetRequest(AssetModel createAsset)
 {
     CreateAsset = createAsset;
 }
        public ActionResult AddAssetModel(AddAssetModelViewModel vm)
        {
            var Success = false;
            var Message = "";

            var categoryValidation = AssetModel.Validator.ValidateCategory(vm.SelectedCategoryId);

            if (categoryValidation != null)
            {
                ModelState.AddModelError("Category", categoryValidation);
            }

            var nameValidation = AssetModel.Validator.ValidateName(null, vm.Name, vm.SelectedCategoryId);

            if (nameValidation != null)
            {
                ModelState.AddModelError("Name", nameValidation);
            }

            if (vm.Properties != null)
            {
                var hasPropertyErrors = false;
                for (var i = 0; i < vm.Properties.Count; i++)
                {
                    var propertyValidation = AssetModel.Validator.ValidateProperty(vm.Properties[i].Name);
                    if (propertyValidation != null)
                    {
                        ModelState.AddModelError($"Properties[{i}].Name", propertyValidation);
                        hasPropertyErrors = true;
                    }
                }

                if (!hasPropertyErrors)
                {
                    var properties = (from p in vm.Properties
                                      select new Tuple <string, bool>(p.Name, p.IsNumeric)).ToList();
                    var propertiesValidation = AssetModel.Validator.ValidateProperties(properties);
                    if (propertiesValidation != null)
                    {
                        ModelState.AddModelError("Properties", propertiesValidation);
                    }
                }
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var newModel = new AssetModel
                    {
                        AssetModelCategoryId = vm.SelectedCategoryId,
                        Name       = vm.Name,
                        Properties = new List <AssetModelProperty>(),
                    };
                    if (vm.Properties != null)
                    {
                        foreach (var p in vm.Properties)
                        {
                            newModel.Properties.Add(new AssetModelProperty
                            {
                                AssetModel = newModel,
                                Name       = p.Name,
                                IsNumeric  = p.IsNumeric,
                            });
                        }
                    }
                    db.AssetModels.Add(newModel);
                    db.SaveChanges();

                    Success = true;
                    Message = AssetModel.SAVE_SUCCESS;
                }
                catch (Exception e)
                {
                    Message = AssetModel.SAVE_FAIL;
                }
                return(Json(new { Success, Message }));
            }
            vm.Categories = db.CategoryDropdown();
            return(PartialView("_AddAssetModel", vm));
        }
Example #6
0
 private void Jtask_AssetUpdated(string AssetRef, AssetModel asset)
 {
     if (!Assets.ContainsKey(AssetRef))
         Assets[AssetRef] = asset;
 }
Example #7
0
 public void Load(Action onLoaded)
 {
     model = AssetModelFactory.CreateModel(AssetType.UI_PANEL, res);
     model.Load(OnLoaded + onLoaded);
 }
Example #8
0
        public IActionResult GetNextEmp(string cls, string docid /*, string vendor*/)
        {
            List <SelectListItem> list = new List <SelectListItem>();
            List <string>         s;
            SelectListItem        li;
            AppUserModel          u;
            RepairModel           r     = _context.BMEDRepairs.Find(docid);
            AssetModel            asset = _context.BMEDAssets.Where(a => a.AssetNo == r.AssetNo).FirstOrDefault();

            switch (cls)
            {
            case "維修工程師":
                roleManager.GetUsersInRole("Engineer").ToList()
                .ForEach(x =>
                {
                    u = _context.AppUsers.Where(ur => ur.UserName == x).FirstOrDefault();
                    if (u != null)
                    {
                        li       = new SelectListItem();
                        li.Text  = u.FullName;
                        li.Value = u.Id.ToString();
                        list.Add(li);
                    }
                });
                break;

            case "醫工主管":
                s    = roleManager.GetUsersInRole("MedMgr").ToList();
                list = new List <SelectListItem>();
                foreach (string l in s)
                {
                    u = _context.AppUsers.Where(ur => ur.UserName == l).FirstOrDefault();
                    if (!string.IsNullOrEmpty(u.DptId))
                    {
                        li       = new SelectListItem();
                        li.Text  = u.FullName + "(" + u.UserName + ")";
                        li.Value = u.Id.ToString();
                        list.Add(li);
                    }
                }
                break;

            case "賀康主管":     //設備主管
                s    = roleManager.GetUsersInRole("MedAssetMgr").ToList();
                list = new List <SelectListItem>();
                foreach (string l in s)
                {
                    u = _context.AppUsers.Where(ur => ur.UserName == l).FirstOrDefault();
                    if (!string.IsNullOrEmpty(u.DptId))
                    {
                        li       = new SelectListItem();
                        li.Text  = u.FullName + "(" + u.UserName + ")";
                        li.Value = u.Id.ToString();
                        list.Add(li);
                    }
                }
                break;

            case "醫工主任":
                s    = roleManager.GetUsersInRole("MedDirector").ToList();
                list = new List <SelectListItem>();
                foreach (string l in s)
                {
                    u = _context.AppUsers.Where(ur => ur.UserName == l).FirstOrDefault();
                    if (!string.IsNullOrEmpty(u.DptId))
                    {
                        li       = new SelectListItem();
                        li.Text  = u.FullName + "(" + u.UserName + ")";
                        li.Value = u.Id.ToString();
                        list.Add(li);
                    }
                }
                break;

            case "醫工經辦":
                list = new List <SelectListItem>();
                u    = _context.AppUsers.Where(ur => ur.UserName == "1814").FirstOrDefault();
                if (!string.IsNullOrEmpty(u.DptId))
                {
                    li       = new SelectListItem();
                    li.Text  = u.FullName;
                    li.Value = u.Id.ToString();
                    list.Add(li);
                }
                break;

            case "單位主管":
            case "單位主任":
                //s = roleManager.GetUsersInRole("Manager").ToList();
                /* 擷取申請人單位底下所有人員 */
                //string c = _context.AppUsers.Find(r.UserId).DptId;
                //var dptUsers = _context.AppUsers.Where(a => a.DptId == c).ToList();
                //list = new List<SelectListItem>();
                //foreach (var item in dptUsers)
                //{
                //        li = new SelectListItem();
                //        li.Text = item.FullName;
                //        li.Value = item.Id.ToString();
                //        list.Add(li);
                //}
                break;

            case "單位副院長":
                s    = roleManager.GetUsersInRole("ViceSI").ToList();
                list = new List <SelectListItem>();
                foreach (string l in s)
                {
                    u = _context.AppUsers.Where(ur => ur.UserName == l).FirstOrDefault();
                    if (!string.IsNullOrEmpty(u.DptId))
                    {
                        li       = new SelectListItem();
                        li.Text  = u.FullName + "(" + u.UserName + ")";
                        li.Value = u.Id.ToString();
                        list.Add(li);
                    }
                }
                break;

            case "申請人":
                if (r != null)
                {
                    list     = new List <SelectListItem>();
                    li       = new SelectListItem();
                    li.Text  = r.UserName;
                    li.Value = r.UserId.ToString();
                    list.Add(li);
                }
                else
                {
                    list     = new List <SelectListItem>();
                    li       = new SelectListItem();
                    li.Text  = "宋大衛";
                    li.Value = "000";
                    list.Add(li);
                }
                break;

            case "驗收人":
                if (_context.BMEDRepairEmps.Where(emp => emp.DocId == docid).Count() <= 0)
                {
                    throw new Exception("沒有維修工程師紀錄!!");
                }
                else if (_context.BMEDRepairDtls.Find(docid).EndDate == null)
                {
                    throw new Exception("沒有完工日!!");
                }
                if (r != null)
                {
                    /* 與驗收人同單位的成員(包括驗收人) */
                    var checkerDptId       = _context.AppUsers.Find(r.CheckerId).DptId;
                    List <AppUserModel> ul = _context.AppUsers.Where(f => f.DptId == checkerDptId)
                                             .Where(f => f.Status == "Y").ToList();
                    if (asset != null)
                    {
                        if (asset.DelivDpt != r.DptId)
                        {
                            ul.AddRange(_context.AppUsers.Where(f => f.DptId == asset.DelivDpt)
                                        .Where(f => f.Status == "Y").ToList());
                        }
                    }
                    /* 驗收人 */
                    var checker = _context.AppUsers.Find(r.CheckerId);
                    list     = new List <SelectListItem>();
                    li       = new SelectListItem();
                    li.Text  = checker.FullName + "(" + checker.UserName + ")";
                    li.Value = checker.Id.ToString();
                    list.Add(li);

                    foreach (AppUserModel l in ul)
                    {
                        /* 申請人以外的成員 */
                        if (l.Id != r.UserId)
                        {
                            li       = new SelectListItem();
                            li.Text  = l.FullName + "(" + l.UserName + ")";
                            li.Value = l.Id.ToString();
                            list.Add(li);
                        }
                    }
                }
                break;

            case "設備工程師":

                /* Get all engineers. */
                s = roleManager.GetUsersInRole("MedEngineer").ToList();
                var repEngId = _context.AppUsers.Find(r.EngId).UserName;

                list = new List <SelectListItem>();
                /* 負責工程師 */
                var engTemp = _context.AppUsers.Find(r.EngId);
                li       = new SelectListItem();
                li.Text  = engTemp.FullName + "(" + engTemp.UserName + ")";
                li.Value = engTemp.Id.ToString();
                list.Add(li);
                /* 其他工程師 */
                foreach (string l in s)
                {
                    u = _context.AppUsers.Where(ur => ur.UserName == l).FirstOrDefault();
                    if (u != null && l != repEngId)
                    {
                        li       = new SelectListItem();
                        li.Text  = u.FullName + "(" + u.UserName + ")";
                        li.Value = u.Id.ToString();
                        list.Add(li);
                    }
                }
                break;

            case "列管財產負責人":
                list = new List <SelectListItem>();
                u    = _context.AppUsers.Where(ur => ur.UserName == "181151").FirstOrDefault();
                if (!string.IsNullOrEmpty(u.DptId))
                {
                    li       = new SelectListItem();
                    li.Text  = u.FullName + "(" + u.UserName + ")";
                    li.Value = u.Id.ToString();
                    list.Add(li);
                }
                break;

            case "固資財產負責人":
                list = new List <SelectListItem>();
                u    = _context.AppUsers.Where(ur => ur.UserName == "1814").FirstOrDefault();
                if (!string.IsNullOrEmpty(u.DptId))
                {
                    li       = new SelectListItem();
                    li.Text  = u.FullName + "(" + u.UserName + ")";
                    li.Value = u.Id.ToString();
                    list.Add(li);
                }
                break;

            default:
                list = new List <SelectListItem>();
                break;
            }
            return(Json(list));
        }
Example #9
0
        public static Task <AssetModel> GetAsset(BundleConfig.BundleTypes type, string assetGuid, string name = null,
                                                 IProgress <Tuple <string, float> > progressCallback          = null)
        {
            Init();
            var assetService = new AssetService();
            var found        = assetService.Get(assetGuid);

            if (found != null)
            {
                if (File.Exists(found.LocalPath))
                {
                    return(Task.FromResult(found));
                }
                else
                {
                    Debug.Log($"removing stale entry from assetService due to missing file: {found.LocalPath}");
                    assetService.Delete(assetGuid);
                }
            }

            var typeString = BundleConfig.singularOf(type);

            if (name == null)
            {
                name = typeString;
            }

            string localPath = WebUtilities.GenerateLocalPath(assetGuid, type);

            Uri uri = new Uri(Config.CloudUrl + "/api/v1/assets/download/bundle/" + assetGuid);

            var progressState = new Tuple <string, float>(name, 0.0f);

            progressCallback?.Report(new Tuple <string, float>(name, 0.0f));
            Debug.Log($"{name} Download at 0%");
            var t = new TaskCompletionSource <AssetModel>();

            downloads.Enqueue(new Download(uri, localPath,
                                           progress =>
            {
                progressCallback?.Report(new Tuple <string, float>(name, progress));
                Debug.Log($"{name} Download at {progress}%");
            },
                                           (success, ex) => {
                if (success)
                {
                    try
                    {
                        var model = new AssetModel()
                        {
                            AssetGuid = assetGuid,
                            Type      = typeString,
                            Name      = name,
                            LocalPath = localPath
                        };
                        assetService.Add(model);
                        Debug.Log($"{name} Download Complete.");
                        progressCallback?.Report(new Tuple <string, float>(name, 100));
                        t.TrySetResult(model);
                    }
                    catch (Exception e)
                    {
                        t.TrySetException(e);
                    }
                }
                else
                {
                    t.TrySetException(ex);
                }
            }));
            return(t.Task);
        }
        public ActionResult Create(AssetModel asset)
        {
            if (ModelState.IsValid)
            {
                asset.AssetNo = asset.AssetNo.Trim();
                if (_context.Assets.Find(asset.DeviceNo) != null)
                {
                    throw new Exception("設備編號已經存在!!");
                }
                //if (_context.Assets.Find(asset.AssetNo) != null)
                //{
                //    throw new Exception("財產編號已經存在!!");
                //}
                try
                {
                    asset.DelivEmp = asset.DelivUid == null ? "" : _context.AppUsers.Find(Convert.ToInt32(asset.DelivUid)).FullName;
                    //asset.AssetEngName = asset.AssetEngId == 0 ? "" : _context.AppUsers.Find(asset.AssetEngId).FullName;
                    _context.Assets.Add(asset);
                    AssetKeepModel ak = new AssetKeepModel();
                    ak.DeviceNo = asset.DeviceNo;
                    _context.AssetKeeps.Add(ak);
                    _context.SaveChanges();
                }
                catch (Exception e)
                {
                    throw new Exception(e.Message);
                }

                return(new JsonResult(asset)
                {
                    Value = new { success = true, error = "", id = asset.DeviceNo }
                });
            }
            else
            {
                string msg = "";
                foreach (var error in ViewData.ModelState.Values.SelectMany(modelState => modelState.Errors))
                {
                    msg += error.ErrorMessage + Environment.NewLine;
                }
                throw new Exception(msg);
            }
            //List<SelectListItem> listItem = new List<SelectListItem>();
            //db.Departments.ToList().ForEach(d => {
            //    listItem.Add(new SelectListItem { Text = d.Name_C, Value = d.DptId });
            //});
            //ViewData["DelivDpt"] = new SelectList(listItem, "Value", "Text", "");

            //List<SelectListItem> listItem2 = new List<SelectListItem>();
            //listItem2.Add(new SelectListItem { Text = "", Value = "" });
            //ViewData["DelivUid"] = new SelectList(listItem2, "Value", "Text", "");

            //ViewData["AccDpt"] = new SelectList(listItem, "Value", "Text", "");

            //List<SelectListItem> listItem3 = new List<SelectListItem>();
            //listItem3.Add(new SelectListItem { Text = "正常", Value = "正常" });
            //listItem3.Add(new SelectListItem { Text = "報廢", Value = "報廢" });
            //ViewData["DisposeKind"] = new SelectList(listItem3, "Value", "Text", "");

            //return View(asset);
        }
        // GET: Asset/Edit/5
        public ActionResult Edit(string id)
        {
            if (id == null)
            {
                return(BadRequest());
            }
            AssetModel asset = _context.Assets.Find(id);

            if (asset == null)
            {
                return(StatusCode(404));
            }
            //
            List <SelectListItem> listItem = new List <SelectListItem>();

            _context.Departments.ToList().ForEach(d =>
            {
                listItem.Add(new SelectListItem {
                    Text = d.Name_C, Value = d.DptId
                });
            });
            ViewData["DelivDpt"] = new SelectList(listItem, "Value", "Text", "");

            List <SelectListItem> listItem2 = new List <SelectListItem>();

            _context.AppUsers.Where(u => u.DptId == asset.DelivDpt).ToList().ForEach(u =>
            {
                listItem2.Add(new SelectListItem {
                    Text = u.FullName, Value = u.Id.ToString()
                });
            });
            if (listItem2.Where(item => item.Value == asset.DelivUid.ToString()).Count() == 0)
            {
                listItem2.Add(new SelectListItem {
                    Text = asset.DelivEmp, Value = asset.DelivUid.ToString()
                });
            }
            ViewData["DelivUid"] = new SelectList(listItem2, "Value", "Text", "");

            ViewData["AccDpt"] = new SelectList(listItem, "Value", "Text", "");

            List <SelectListItem> listItem3 = new List <SelectListItem>();

            listItem3.Add(new SelectListItem {
                Text = "正常", Value = "正常"
            });
            listItem3.Add(new SelectListItem {
                Text = "報廢", Value = "報廢"
            });
            ViewData["DisposeKind"] = new SelectList(listItem3, "Value", "Text", "");
            //
            //List<SelectListItem> listItem4 = new List<SelectListItem>();
            //_context.DeviceClassCodes.ToList()
            //    .ForEach(d =>
            //    {
            //        listItem4.Add(new SelectListItem { Text = d.M_name, Value = d.M_code });
            //    });
            //ViewData["BmedNo"] = new SelectList(listItem4, "Value", "Text", "");
            //
            // Get MedEngineers to set dropdownlist.
            var s = roleManager.GetUsersInRole("RepEngineer").ToList();
            List <SelectListItem> listItem5 = new List <SelectListItem>();

            foreach (string l in s)
            {
                AppUserModel u = _context.AppUsers.Where(ur => ur.UserName == l).FirstOrDefault();
                if (u != null)
                {
                    listItem5.Add(new SelectListItem {
                        Text = u.FullName, Value = u.Id.ToString()
                    });
                }
            }
            //ViewData["AssetEngId"] = new SelectList(listItem5, "Value", "Text", "");
            //
            if (asset.VendorId != null)
            {
                asset.VendorName = _context.Vendors.Where(v => v.VendorId == Convert.ToInt32(asset.VendorId)).FirstOrDefault().VendorName;
            }

            return(View(asset));
        }
Example #12
0
        public void Test_NextTask_State_Progress_After_Asset_Assignment_In_First_Task_Without_MOVING_TO_IN_PROGRESS()
        {
            string orderName = "Sample Delivery Order";

            DeliveryOrder order = new DeliveryOrder();

            order.Name = orderName;
            order.From = new DefaultAddress("Test From Address", new Point((new double[] { 1, 2 }).ToList()));
            order.To   = new DefaultAddress("Test To Address", new Point((new double[] { 2, 1 }).ToList()));
            UserModel userModel = new UserModel()
            {
                Email                = "*****@*****.**",
                EmailConfirmed       = false,
                IsUserAuthenticated  = false,
                PhoneNumber          = "+8801684512833",
                PhoneNumberConfirmed = true,
                Profile              = new UserProfile()
                {
                    Address   = new DefaultAddress("Somewhere User belong", new Point(2, 1)),
                    Age       = 26,
                    FirstName = "Gabul",
                    LastName  = "Habul",
                    Gender    = Gender.MALE,
                    PicUri    = null
                },
                Type     = Data.Model.Identity.IdentityTypes.USER,
                UserId   = "123456789",
                UserName = "******"
            };

            var builder = new DeliveryJobBuilder(order, userModel, hridService, paymentMethodMock.Object);

            builder.BuildJob();

            var SampleAssetModel = new AssetModel()
            {
                AverageRating        = 0.0,
                Email                = "*****@*****.**",
                EmailConfirmed       = false,
                PhoneNumber          = "+8801711111111",
                PhoneNumberConfirmed = true,
                Profile              = new UserProfile()
                {
                    Address   = new DefaultAddress("Somewhere User belong", new Point(2, 1)),
                    Age       = 20,
                    FirstName = "John",
                    LastName  = "Doe",
                    Gender    = Gender.MALE,
                    PicUri    = null
                },
                Type     = Data.Model.Identity.IdentityTypes.BIKE_MESSENGER,
                UserId   = "12345678",
                UserName = "******"
            };

            builder.Job.Tasks.First().Asset = SampleAssetModel;
            builder.Job.Tasks.First().State = JobTaskState.IN_PROGRESS;
            builder.Job.Tasks.First().UpdateTask();

            Assert.That(builder.Job.State == JobState.IN_PROGRESS);
            Assert.That(builder.Job.Tasks.First().State == JobTaskState.COMPLETED);
            Assert.That(builder.Job.Tasks[1].State == JobTaskState.IN_PROGRESS);
        }
        public IActionResult EditData(string ano = null, string id = null)
        {
            var ur = _userRepo.Find(usr => usr.UserName == this.User.Identity.Name).FirstOrDefault();

            AssetModel at = _context.BMEDAssets.Find(ano);
            DeliveryModel d = _context.Deliveries.Find(id);
            int vid = d.VendorId != null ? Convert.ToInt32(d.VendorId) : 0;
            VendorModel v = _context.BMEDVendors.Where(vv => vv.VendorId == vid).ToList().FirstOrDefault();
            List<string> s;
            SelectListItem li;
            s = roleManager.GetUsersInRole("Engineer").ToList();
            List<SelectListItem> list = new List<SelectListItem>();
            AppUserModel u;
            foreach (string l in s)
            {
                u = _context.AppUsers.Where(usr => usr.UserName == l).FirstOrDefault();
                if (u != null)
                {
                    if (u.VendorId != null)
                    {
                        if (u.VendorId == v.VendorId)
                        {
                            li = new SelectListItem();
                            li.Text = u.FullName;
                            li.Value = u.Id.ToString();
                            list.Add(li);
                        }
                    }
                }
            }
            DepartmentModel dpt = _context.Departments.Find(at.DelivDpt);
            DepartmentModel g;
            if (dpt != null)
            {
                s = roleManager.GetUsersInRole("MedEngineer").ToList();
                foreach (string l in s)
                {
                    u = _context.AppUsers.Where(usr => usr.UserName == l).FirstOrDefault();
                    if (u != null)
                    {
                        if (u.DptId != null)
                        {
                            g = _context.Departments.Find(u.DptId);
                            if (g.DptId == dpt.DptId)
                            {
                                li = new SelectListItem();
                                li.Text = u.FullName;
                                li.Value = u.Id.ToString();
                                list.Add(li);
                            }
                        }
                    }
                }
            }
            ViewData["Items"] = new SelectList(list, "Value", "Text", "");
            List<SelectListItem> listItem = new List<SelectListItem>();
            listItem.Add(new SelectListItem { Text = "自行", Value = "自行" });
            listItem.Add(new SelectListItem { Text = "委外", Value = "委外" });
            listItem.Add(new SelectListItem { Text = "保固", Value = "保固" });
            listItem.Add(new SelectListItem { Text = "租賃", Value = "租賃" });
            ViewData["INOUTITEMS"] = new SelectList(listItem, "Value", "Text", "");
            //
            List<SelectListItem> list2 = new List<SelectListItem>();
            List<KeepFormatModel> kf = _context.BMEDKeepFormats.ToList();
            foreach (KeepFormatModel k in kf)
            {
                li = new SelectListItem { Text = k.FormatId, Value = k.FormatId };
                list2.Add(li);
            }
            ViewData["FORMATITEMS"] = new SelectList(list2, "Value", "Text", "");
            //
            AssetKeepModel assetkeep = _context.BMEDAssetKeeps.Find(ano);
            if (assetkeep == null)
            {
                return NotFound();
            }
            assetkeep.Cname = _context.BMEDAssets.Find(assetkeep.AssetNo).Cname;
            if (assetkeep.KeepYm == null)
            {
                assetkeep.KeepYm = (d.DelivDateR.Year - 1911) * 100 + d.DelivDateR.Month;
            }
            return PartialView(assetkeep);
        }
Example #14
0
 private void JobTask_AssetUpdated(string AssetRef, AssetModel asset)
 {
     //FIXME: Replicating code constantly, need to fix these
     if (!job.Assets.ContainsKey(AssetRef))
         job.Assets[AssetRef] = asset;
 }
Example #15
0
        private AssetModel GetDummyAssetModel()
        {
            var assetModel = new AssetModel()
            {
                AverageRating = 3.2,
                Email = "someAsset @asset.com",
                EmailConfirmed = true,
                IsUserAuthenticated = true,
                PhoneNumber = "123456789",
                PhoneNumberConfirmed = true,
                Profile = new AssetProfile()
                {
                    Address = new DefaultAddress("Somewhere in the world", new Point(1,2)),
                    Age = 25,
                    DriversLicenseId = "123456",
                    FirstName = "Some",
                    LastName = "Asset",
                    Gender = Gender.MALE,
                    NationalId = "e123r123",
                    PicUri = "http://some-pic-uri.img"
                },
                Type = IdentityTypes.BIKE_MESSENGER,
                UserId = "123456789",
                UserName = "******"
            };

            return assetModel;
        }
Example #16
0
        public ActionResult GetNextEmp(string cls, string docid/*, string vendor*/)
        {
            List<SelectListItem> list = new List<SelectListItem>();
            List<string> s;
            SelectListItem li;
            AppUserModel u;
            KeepModel k = _context.BMEDKeeps.Find(docid);
            AssetModel asset = _context.BMEDAssets.Where(a => a.AssetNo == k.AssetNo).FirstOrDefault();
            string[] locList;

            switch (cls)
            {
                case "維修工程師":  //Not Used
                    roleManager.GetUsersInRole("Engineer").ToList()
                        .ForEach(x =>
                        {
                            u = _context.AppUsers.Where(ur => ur.UserName == x).FirstOrDefault();
                            if (u != null)
                            {
                                li = new SelectListItem();
                                li.Text = u.FullName + "(" + u.UserName + ")";
                                li.Value = u.Id.ToString();
                                list.Add(li);
                            }
                        });
                    break;
                case "醫工主管":
                    s = roleManager.GetUsersInRole("MedMgr").ToList();
                    list = new List<SelectListItem>();
                    foreach (string l in s)
                    {
                        u = _context.AppUsers.Where(ur => ur.UserName == l).FirstOrDefault();
                        if (!string.IsNullOrEmpty(u.DptId))
                        {
                            li = new SelectListItem();
                            li.Text = u.FullName + "(" + u.UserName + ")";
                            li.Value = u.Id.ToString();
                            list.Add(li);
                        }
                    }
                    break;
                case "賀康主管":  //設備主管
                    s = roleManager.GetUsersInRole("MedAssetMgr").ToList();
                    list = new List<SelectListItem>();
                    foreach (string l in s)
                    {
                        u = _context.AppUsers.Where(ur => ur.UserName == l).FirstOrDefault();
                        if (!string.IsNullOrEmpty(u.DptId))
                        {
                            li = new SelectListItem();
                            li.Text = u.FullName + "(" + u.UserName + ")";
                            li.Value = u.Id.ToString();
                            list.Add(li);
                        }
                    }
                    if (k.Loc == "總院")
                    {
                        list.Remove(list.Single(x => x.Value == "1129"));
                    }
                    else
                    {
                        list.Remove(list.Single(x => x.Value == "12549"));
                    }
                    break;
                case "醫工主任":  //Not Used
                    s = roleManager.GetUsersInRole("MedDirector").ToList();
                    list = new List<SelectListItem>();
                    foreach (string l in s)
                    {
                        u = _context.AppUsers.Where(ur => ur.UserName == l).FirstOrDefault();
                        if (!string.IsNullOrEmpty(u.DptId))
                        {
                            li = new SelectListItem();
                            li.Text = u.FullName + "(" + u.UserName + ")";
                            li.Value = u.Id.ToString();
                            list.Add(li);
                        }
                    }
                    break;
                case "醫工經辦":  //Not Used
                    //list = new List<SelectListItem>();
                    //u = _context.AppUsers.Where(ur => ur.UserName == "1814").FirstOrDefault();
                    //if (!string.IsNullOrEmpty(u.DptId))
                    //{
                    //    li = new SelectListItem();
                    //    li.Text = u.FullName;
                    //    li.Value = u.Id.ToString();
                    //    list.Add(li);
                    //}
                    break;
                case "單位主管":
                    /* Get login user. */
                    u = _userRepo.Find(ur => ur.UserName == this.User.Identity.Name).FirstOrDefault();
                    /* Get login user's location. */
                    var urLocation = new DepartmentModel(_context).GetUserLocation(u);
                    if (urLocation != "總院")
                    {
                        s = roleManager.GetUsersInRole("Manager").OrderBy(x => x).ToList();
                        list = new List<SelectListItem>();
                        li = new SelectListItem();
                        li.Text = "請選擇";
                        li.Value = "請選擇";
                        list.Add(li);
                        //
                        locList = new[] { "K", "P", "C" };
                        if (k.Loc != "總院")
                        {
                            Array.Clear(locList, 0, locList.Length);
                            locList = new[] { k.Loc };
                        }
                        foreach (string l in s)
                        {
                            u = _context.AppUsers.Where(ur => !string.IsNullOrEmpty(ur.DptId))
                            .Join(_context.Departments, ur => ur.DptId, d => d.DptId, (ur, d) => new
                            {
                                appuser = ur,
                                dpt = d
                            })
                            .Where(d => locList.Contains(d.dpt.Loc))
                            .Where(ur => ur.appuser.UserName == l && ur.appuser.Status == "Y").Select(ur => ur.appuser).FirstOrDefault();
                            if (u != null)
                            {
                                li = new SelectListItem();
                                li.Text = u.FullName + "(" + u.UserName + ")";
                                li.Value = u.Id.ToString();
                                list.Add(li);
                            }
                        }
                    }
                    else
                    {
                        list = new List<SelectListItem>();
                        li = new SelectListItem();
                        li.Text = "請選擇";
                        li.Value = "請選擇";
                        list.Add(li);
                        //
                        _context.AppUsers.Where(ur => !string.IsNullOrEmpty(ur.DptId))
                        .Where(ur => ur.DptId == k.DptId)
                        .Where(ur => ur.Status == "Y")
                        .ToList()
                        .ForEach(ur => {
                            li = new SelectListItem();
                            li.Text = ur.FullName + "(" + ur.UserName + ")";
                            li.Value = ur.Id.ToString();
                            list.Add(li);
                        });
                    }
                    break;
                case "單位主任":  //Not Used
                    break;
                case "單位副院長":  //Not Used
                    s = roleManager.GetUsersInRole("ViceSI").ToList();
                    list = new List<SelectListItem>();
                    foreach (string l in s)
                    {
                        u = _context.AppUsers.Where(ur => ur.UserName == l).FirstOrDefault();
                        if (!string.IsNullOrEmpty(u.DptId))
                        {
                            li = new SelectListItem();
                            li.Text = u.FullName + "(" + u.UserName + ")";
                            li.Value = u.Id.ToString();
                            list.Add(li);
                        }
                    }
                    break;
                case "申請人":
                    if (k != null)
                    {
                        list = new List<SelectListItem>();
                        li = new SelectListItem();
                        li.Text = k.UserName;
                        li.Value = k.UserId.ToString();
                        list.Add(li);
                    }
                    else
                    {
                        list = new List<SelectListItem>();
                        li = new SelectListItem();
                        li.Text = "宋大衛";
                        li.Value = "000";
                        list.Add(li);
                    }
                    break;
                case "驗收人":
                    if (_context.BMEDKeepEmps.Where(emp => emp.DocId == docid).Count() <= 0)
                    {
                        throw new Exception("沒有維修工程師紀錄!!");
                    }
                    else if (_context.BMEDKeepDtls.Find(docid).EndDate == null)
                    {
                        throw new Exception("沒有完工日!!");

                    }
                    else if (_context.BMEDKeepDtls.Find(docid).Result == null ||
                        _context.BMEDKeepDtls.Find(docid).Result == null)
                    {
                        throw new Exception("沒有保養結果!!");
                    }
                    if (k != null)
                    {
                        if (k.Src != "M")// 非手動出單
                        {
                            /* 成本中心的成員 */
                            List<AppUserModel> ul = _context.AppUsers.Where(f => f.DptId == k.AccDpt)
                                                                     .Where(f => f.Status == "Y").ToList();
                            /* 驗收人列表 */
                            list = new List<SelectListItem>();
                            li = new SelectListItem();
                            li.Text = "請選擇";
                            li.Value = null;
                            list.Add(li);

                            foreach (AppUserModel l in ul)
                            {
                                li = new SelectListItem();
                                li.Text = l.FullName + "(" + l.UserName + ")";
                                li.Value = l.Id.ToString();
                                list.Add(li);
                            }
                        }
                        else
                        {
                            /* 與驗收人同單位的成員(包括驗收人) */
                            var checkerDptId = _context.AppUsers.Find(k.CheckerId).DptId;
                            List<AppUserModel> ul = _context.AppUsers.Where(f => f.DptId == checkerDptId)
                                                                     .Where(f => f.Status == "Y").ToList();
                            if (asset != null)
                            {
                                if (asset.DelivDpt != k.DptId)
                                {
                                    ul.AddRange(_context.AppUsers.Where(f => f.DptId == asset.DelivDpt)
                                                                 .Where(f => f.Status == "Y").ToList());
                                }
                            }
                            /* 驗收人 */
                            var checker = _context.AppUsers.Find(k.CheckerId);
                            list = new List<SelectListItem>();
                            li = new SelectListItem();
                            li.Text = checker.FullName + "(" + checker.UserName + ")";
                            li.Value = checker.Id.ToString();
                            list.Add(li);

                            foreach (AppUserModel l in ul)
                            {
                                /* 申請人以外的成員 */
                                if (l.Id != k.UserId)
                                {
                                    li = new SelectListItem();
                                    li.Text = l.FullName + "(" + l.UserName + ")";
                                    li.Value = l.Id.ToString();
                                    list.Add(li);
                                }
                            }
                        }
                    }
                    break;
                case "設備工程師":

                    /* Get all engineers. */
                    s = roleManager.GetUsersInRole("MedEngineer").OrderBy(x => x).ToList();
                    var keepEngId = _context.BMEDAssetKeeps.Find(k.AssetNo).KeepEngId;
                    var keepEng = _context.AppUsers.Find(keepEngId);

                    list = new List<SelectListItem>();
                    /* 負責工程師 */
                    li = new SelectListItem();
                    li.Text = keepEng.FullName + "(" + keepEng.UserName + ")";
                    li.Value = keepEng.Id.ToString();
                    list.Add(li);
                    /* 其他工程師 */
                    locList = new[] { "K", "P", "C" };
                    if (k.Loc != "總院")
                    {
                        Array.Clear(locList, 0, locList.Length);
                        locList = new[] { k.Loc };
                    }
                    foreach (string l in s)
                    {
                        u = _context.AppUsers.Where(ur => !string.IsNullOrEmpty(ur.DptId))
                            .Join(_context.Departments, ur => ur.DptId, d => d.DptId, (ur, d) => new
                            {
                                appuser = ur,
                                dpt = d
                            })
                            .Where(d => locList.Contains(d.dpt.Loc))
                            .Where(ur => ur.appuser.UserName == l && ur.appuser.Status == "Y").Select(ur => ur.appuser).FirstOrDefault();

                        if (u != null && l != keepEng.UserName)
                        {
                            li = new SelectListItem();
                            li.Text = u.FullName + "(" + u.UserName + ")";
                            li.Value = u.Id.ToString();
                            list.Add(li);
                        }
                    }
                    break;
                case "列管財產負責人":  //Not Used
                    //list = new List<SelectListItem>();
                    //u = _context.AppUsers.Where(ur => ur.UserName == "181151").FirstOrDefault();
                    //if (!string.IsNullOrEmpty(u.DptId))
                    //{
                    //    li = new SelectListItem();
                    //    li.Text = u.FullName;
                    //    li.Value = u.Id.ToString();
                    //    list.Add(li);
                    //}
                    break;
                case "固資財產負責人":  //Not Used
                    //list = new List<SelectListItem>();
                    //u = _context.AppUsers.Where(ur => ur.UserName == "1814").FirstOrDefault();
                    //if (!string.IsNullOrEmpty(u.DptId))
                    //{
                    //    li = new SelectListItem();
                    //    li.Text = u.FullName;
                    //    li.Value = u.Id.ToString();
                    //    list.Add(li);
                    //}
                    break;
                case "醫工分院主管":
                    s = roleManager.GetUsersInRole("MedBranchMgr").OrderBy(x => x).ToList();
                    list = new List<SelectListItem>();
                    locList = new[] { k.Loc };
                    foreach (string l in s)
                    {
                        u = _context.AppUsers.Where(ur => !string.IsNullOrEmpty(ur.DptId))
                            .Join(_context.Departments, ur => ur.DptId, d => d.DptId, (ur, d) => new
                            {
                                appuser = ur,
                                dpt = d
                            })
                            .Where(d => locList.Contains(d.dpt.Loc))
                            .Where(ur => ur.appuser.UserName == l && ur.appuser.Status == "Y").Select(ur => ur.appuser).FirstOrDefault();
                        if (u != null)
                        {
                            li = new SelectListItem();
                            li.Text = u.FullName + "(" + u.UserName + ")";
                            li.Value = u.Id.ToString();
                            list.Add(li);
                        }
                    }
                    break;
                case "設備主管":
                    s = roleManager.GetUsersInRole("DeviceMgr").OrderBy(x => x).ToList();
                    list = new List<SelectListItem>();
                    locList = new[] { "K", "P", "C" };
                    if (k.Loc != "總院")
                    {
                        Array.Clear(locList, 0, locList.Length);
                        locList = new[] { k.Loc };
                    }
                    foreach (string l in s)
                    {
                        u = _context.AppUsers.Where(ur => !string.IsNullOrEmpty(ur.DptId))
                            .Join(_context.Departments, ur => ur.DptId, d => d.DptId, (ur, d) => new
                            {
                                appuser = ur,
                                dpt = d
                            })
                            .Where(d => locList.Contains(d.dpt.Loc))
                            .Where(ur => ur.appuser.UserName == l && ur.appuser.Status == "Y").Select(ur => ur.appuser).FirstOrDefault();
                        if (u != null)
                        {
                            li = new SelectListItem();
                            li.Text = u.FullName + "(" + u.UserName + ")";
                            li.Value = u.Id.ToString();
                            list.Add(li);
                        }
                    }
                    break;
                default:
                    list = new List<SelectListItem>();
                    break;
            }
            return Json(list);
        }
Example #17
0
        // FIXME: I can definitely put this over in the job or at least put a
        // virtual function if just nothing except assigning to the dictionary 
        // happens

        private void JobTask_AssetUpdated(string AssetRef, AssetModel asset)
        {
            if (!job.Assets.ContainsKey(AssetRef))
                job.Assets[AssetRef] = asset; // FIXME: I definitely need to fix it here, database fetch needed, dont know how this should work out
        }
Example #18
0
        public HttpResponseMessage SaveAssetModel(AssetModel a)
        {
            //connect to database
            SqlConnection conn = new SqlConnection();

            try
            {
                //connetionString="Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password"
                conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["EES_DB_ConnectionString"].ToString();

                SqlCommand cmd = new SqlCommand();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "InsUpdDelAssetModels";
                cmd.Connection  = conn;
                conn.Open();


                SqlParameter Gid = new SqlParameter();
                Gid.ParameterName = "@name";
                Gid.SqlDbType     = SqlDbType.VarChar;
                Gid.Value         = a.Name;
                cmd.Parameters.Add(Gid);

                SqlParameter Gim = new SqlParameter();
                Gim.ParameterName = "@Id";
                Gim.SqlDbType     = SqlDbType.Int;
                Gim.Value         = Convert.ToString(a.Id);
                cmd.Parameters.Add(Gim);

                SqlParameter pid = new SqlParameter();
                pid.ParameterName = "@desc";
                pid.SqlDbType     = SqlDbType.VarChar;
                pid.Value         = a.Description;
                cmd.Parameters.Add(pid);

                SqlParameter llid = new SqlParameter();
                llid.ParameterName = "@assetModelTypeId";
                llid.SqlDbType     = SqlDbType.Int;
                llid.Value         = a.AssetTypeId;
                cmd.Parameters.Add(llid);

                SqlParameter flag = new SqlParameter();
                flag.ParameterName = "@change";
                flag.SqlDbType     = SqlDbType.VarChar;
                flag.Value         = a.insupddelflag;
                cmd.Parameters.Add(flag);

                cmd.ExecuteScalar();
                conn.Close();
                //Logger.Trace(LogCategory.WebApp, "SaveAssetModel() procedure executed successfully.", LogLevel.Information, null);
                return(new HttpResponseMessage(HttpStatusCode.OK));
            }
            catch (Exception ex)
            {
                if (conn != null && conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
                string str = ex.Message;

                //Logger.Error(ex, LogCategory.WebApp, "An error occured in SaveAssetModel() procedure", LogLevel.Error, null);
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
            }
        }
        public void Test_NextTask_State_Progress_After_Asset_Assignment_In_First_Task_Without_MOVING_TO_IN_PROGRESS()
        {
            string orderName = "Sample Delivery Order";

            DeliveryOrder order = new DeliveryOrder();
            order.Name = orderName;
            order.From = new DefaultAddress("Test From Address", new Point((new double[] { 1, 2 }).ToList()));
            order.To = new DefaultAddress("Test To Address", new Point((new double[] { 2, 1 }).ToList()));
            UserModel userModel = new UserModel()
            {
                Email = "*****@*****.**",
                EmailConfirmed = false,
                IsUserAuthenticated = false,
                PhoneNumber = "+8801684512833",
                PhoneNumberConfirmed = true,
                Profile = new UserProfile()
                {
                    Address = new DefaultAddress("Somewhere User belong", new Point(2, 1)),
                    Age = 26,
                    FirstName = "Gabul",
                    LastName = "Habul",
                    Gender = Gender.MALE,
                    PicUri = null
                },
                Type = Data.Model.Identity.IdentityTypes.USER,
                UserId = "123456789",
                UserName = "******"
            };

            var builder = new DeliveryJobBuilder(order, userModel, hridService, paymentMethodMock.Object);
            builder.BuildJob();

            var SampleAssetModel = new AssetModel()
            {
                AverageRating = 0.0,
                Email = "*****@*****.**",
                EmailConfirmed = false,
                PhoneNumber = "+8801711111111",
                PhoneNumberConfirmed = true,
                Profile = new UserProfile()
                {
                    Address = new DefaultAddress("Somewhere User belong", new Point(2, 1)),
                    Age = 20,
                    FirstName = "John",
                    LastName = "Doe",
                    Gender = Gender.MALE,
                    PicUri = null
                },
                Type = Data.Model.Identity.IdentityTypes.BIKE_MESSENGER,
                UserId = "12345678",
                UserName = "******"
            };

            builder.Job.Tasks.First().Asset = SampleAssetModel;
            builder.Job.Tasks.First().State = JobTaskState.IN_PROGRESS;
            builder.Job.Tasks.First().UpdateTask();

            Assert.That(builder.Job.State == JobState.IN_PROGRESS);
            Assert.That(builder.Job.Tasks.First().State == JobTaskState.COMPLETED);
            Assert.That(builder.Job.Tasks[1].State == JobTaskState.IN_PROGRESS);
        }
Example #20
0
 public void OnDialogOpened(IDialogParameters parameters)
 {
     Asset = parameters.GetValue <AssetModel>("asset");
 }