public async Task OnGetAsync(Guid id)
        {
            try
            {
                var resultUser = await apiHttpClient.Get <UserItem>("/api/User/GetByToken/" + User.Claims.First(x => x.Type == ClaimTypes.NameIdentifier).Value);

                if (!resultUser.Succeeded || resultUser.Data.CompanyList == null || !resultUser.Data.CompanyList.Any())
                {
                    Response.Redirect("/");
                }

                var result = await apiHttpClient.Get <DeclarationItem>("/api/Declaration/Get/" + id);

                if (result.Succeeded)
                {
                    ViewData.Add("Done", $"<div class='feedback-summary-header'><span>{localizer["Self-control sent in"]}</span></div>");

                    DeclarationItemForm = result.Data;
                }
                else
                {
                    await errorHandler.View(this, null, result.Exception);
                }
            }
            catch (Exception exception)
            {
                await errorHandler.Log(this, null, exception, id);
            }
        }
        public async Task OnGetAsync(Guid id)
        {
            try
            {
                var resultUser = await apiHttpClient.Get <UserItem>("/api/User/GetByToken/" + User.Claims.First(x => x.Type == ClaimTypes.NameIdentifier).Value);

                if (!resultUser.Succeeded || resultUser.Data.CompanyList == null || !resultUser.Data.CompanyList.Any())
                {
                    Response.Redirect("/");
                }

                var result = await apiHttpClient.Get <DeclarationItem>("/api/Declaration/Get/" + id);

                if (result.Succeeded)
                {
                    DeclarationItemForm = result.Data;

                    if (DeclarationItemForm.Status.Id == (int)DeclarationStatus.SentIn)
                    {
                        Response.Redirect("/Declaration/DeclarationList");
                    }
                }
                else
                {
                    await errorHandler.View(this, null, result.Exception);
                }
            }
            catch (Exception exception)
            {
                await errorHandler.Log(this, null, exception, id);
            }
        }
Пример #3
0
        public async Task OnGetAsync(Guid id)
        {
            try
            {
                var result = await apiHttpClient.Get <DeclarationItem>("/api/Declaration/Get/" + id);

                if (result.Succeeded)
                {
                    DeclarationItemForm = result.Data;

                    if (DeclarationItemForm.Status.Id == (int)DeclarationStatus.SentIn)
                    {
                        Response.Redirect("/Declaration/DeclarationList");
                    }
                }
                else
                {
                    await errorHandler.View(this, null, result.Exception);
                }
            }
            catch (Exception exception)
            {
                await errorHandler.Log(this, null, exception, id);
            }
        }
Пример #4
0
        public ApiResult Add(DeclarationItem declarationItem)
        {
            var result = new ApiResult();

            try
            {
                declarationItem.Id            = Guid.NewGuid();
                declarationItem.CreatedDate   = DateTime.Now;
                declarationItem.StatusId      = (int)DeclarationStatus.Created;
                declarationItem.UserItemId    = userRepository.Get <UserItem>(declarationItem.UserItemId).Data.Id;
                declarationItem.IndicatorList = new List <DeclarationIndicatorGroup>();

                declarationItem.DeclarationTestItem = new DeclarationTestItem
                {
                    Id              = declarationItem.Id,
                    TypeOfMachine   = dbContext.VlTypeOfMachineList.Single(x => x.Id == 1),
                    TypeOfTest      = dbContext.VlTypeOfTestList.Single(x => x.Id == 1),
                    PurposeOfTestId = declarationItem.DeclarationTestItem.PurposeOfTestId
                };

                foreach (var indicatorTestGroup in dbContext.IndicatorTestGroupList.Include(x => x.IndicatorItem).Include(x => x.TestGroupItem))
                {
                    declarationItem.IndicatorList.Add(new DeclarationIndicatorGroup
                    {
                        IndicatorItem             = indicatorTestGroup.IndicatorItem,
                        TestGroupOrder            = indicatorTestGroup.TestGroupItem.Order,
                        IndicatorInTestGroupOrder = indicatorTestGroup.Order,
                        TestGroupItemId           = indicatorTestGroup.TestGroupItemId
                    });
                }

                if (!String.IsNullOrEmpty(declarationItem.UserName))
                {
                    var user = dbContext.UserList.SingleOrDefault(x => x.Name == declarationItem.UserName);

                    if (user != null)
                    {
                        declarationItem.UserItemId = user.Id;
                    }
                }

                dbContext.DeclarationList.Add(declarationItem);
                dbContext.SaveChanges();

                result.Succeeded = true;
                result.Id        = declarationItem.Id;
            }
            catch (Exception exception)
            {
                result.Succeeded = false;
                result.Exception = exception;
            }

            return(result);
        }
        public async Task OnGetAsync(Guid id, Guid companyId)
        {
            try
            {
                if (await CreateLists())
                {
                    if (id != Guid.Empty)
                    {
                        var result = await apiHttpClient.Get <DeclarationItem>("/api/Declaration/Get/" + id);

                        if (result.Succeeded)
                        {
                            DeclarationItemForm = result.Data;

                            await GetOutcomeDataList(id);

                            FilterStatusList();
                        }
                        else
                        {
                            await errorHandler.View(this, null, result.Exception);
                        }
                    }
                    else
                    {
                        var result = await apiHttpClient.Get <CompanyItem>("/api/Company/Get/" + companyId);

                        if (result.Succeeded)
                        {
                            DeclarationItemForm = new DeclarationItem
                            {
                                Company             = result.Data,
                                CompanyItemId       = companyId,
                                UserItemId          = Guid.Parse(User.Claims.First(x => x.Type == ClaimTypes.PrimarySid).Value),
                                DeadlineDate        = DateTime.Now.Date.AddDays(14).AddHours(23).AddMinutes(59),
                                DeclarationTestItem = new DeclarationTestItem
                                {
                                    TypeOfMachine   = ValueListTypeOfMachine.Single(x => x.Id == 1),
                                    TypeOfTest      = ValueListTypeOfTest.Single(x => x.Id == 1),
                                    PurposeOfTestId = 2
                                }
                            };
                        }
                        else
                        {
                            await errorHandler.View(this, null, result.Exception);
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                await errorHandler.Log(this, null, exception, id, companyId);
            }
        }
        public ApiResult Update(DeclarationItem declarationItem)
        {
            var declarationItemBefore = declarationItem.DeepClone();

            var result = inner.Update(declarationItem);

            if (!result.Succeeded && LogError || result.Succeeded && LogChangeSucceeded || stopwatch.ElapsedMilliseconds > LogLongTime)
            {
                logRepository.Add(new LogItem(stopwatch, userId, declarationItem.CompanyItemId, result, declarationItemBefore));
            }

            return(result);
        }
Пример #7
0
        public ApiResult Update(DeclarationItem declarationItem)
        {
            var result = new ApiResult();

            try
            {
                var dbItem = dbContext.DeclarationList.Include(x => x.DeclarationTestItem).Single(x => x.Id == declarationItem.Id);

                if (dbItem == null)
                {
                    throw new InvalidOperationException(localizer["Declaration with id: {0} doesn't exist.", declarationItem.Id]);
                }

                dbItem.Name         = declarationItem.Name;
                dbItem.CaseNumber   = declarationItem.CaseNumber;
                dbItem.DeadlineDate = declarationItem.DeadlineDate;
                dbItem.StatusId     = declarationItem.StatusId;
                dbItem.UserItemId   = userRepository.Get <UserItem>(declarationItem.UserItemId).Data.Id;
                dbItem.DeclarationTestItem.PurposeOfTestId = declarationItem.DeclarationTestItem.PurposeOfTestId;

                if (declarationItem.StatusId == (int)DeclarationStatus.Finished || declarationItem.StatusId == (int)DeclarationStatus.Canceled)
                {
                    var companyItem = dbContext.CompanyList.Include(x => x.UserList).ThenInclude(x => x.UserItem).AsNoTracking().SingleOrDefault(x => x.Id == declarationItem.CompanyItemId);

                    if (companyItem != null)
                    {
                        foreach (var userCompany in companyItem.UserList)
                        {
                            var user = dbContext.UserList.SingleOrDefault(x => x.Id == userCompany.UserItemId);

                            dbContext.UserList.Remove(user ?? throw new InvalidOperationException());
                        }

                        companyItem.Code = string.Empty;
                    }
                }

                dbContext.SaveChanges();

                result.Succeeded = true;
                result.Id        = declarationItem.Id;
            }
            catch (Exception exception)
            {
                result.Succeeded = false;
                result.Exception = exception;
            }

            return(result);
        }
Пример #8
0
        public ApiResult Update(DeclarationItem declarationItem)
        {
            ClearCache(declarationItem.Id, declarationItem.CompanyItemId);

            return(inner.Update(declarationItem));
        }
 public ApiResult Update(DeclarationItem declarationItem)
 {
     return(HandleRequest() ?? declarationRepository.Update(declarationItem));
 }
 public ApiResult Add(DeclarationItem declarationItem)
 {
     return(HandleRequest() ?? declarationRepository.Add(declarationItem));
 }