Example #1
0
        public async Task <ActionResult> Edit(Guid id, EditAnchorViewModel request)
        {
            if (!ModelState.IsValid)
            {
                Alert("Invalid Request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(View());
            }
            if (!id.Equals(request.AnchorId))
            {
                Alert("Invalid Request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(View());
            }
            try
            {
                var updateAnchorRequest = new UpdateAnchorRequest
                {
                    Id          = request.AnchorId,
                    Name        = request.Name,
                    Description = request.Description
                };
                var result = await _anchorService.Update(id, updateAnchorRequest);

                if (!result.Success)
                {
                    Alert($"Error: {result.Message}", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                    return(View());
                }

                Alert($"Anchor Updated Successfully", NotificationType.success, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                Alert($"Error Occurred While processing the request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(View());
            }
        }
Example #2
0
        // GET: Anchors/Edit/5
        public async Task <ActionResult> Edit(Guid id)
        {
            var tiersResult = await _tierService.FindById(id);

            if (!tiersResult.Success)
            {
                Alert($"{tiersResult.Message}", NotificationType.info, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                ViewBag.Tiers = null;
            }
            else
            {
                ViewBag.Tiers = tiersResult.Data;
            }

            var countryResult = await _countryService.FindAll();

            if (!countryResult.Success)
            {
                Alert($"{tiersResult.Message}", NotificationType.info, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                ViewBag.Countries = null;
            }
            else
            {
                ViewBag.Countries = countryResult.Data;
            }

            var etypeResult = await _entityTypeService.FindAll();

            if (!etypeResult.Success)
            {
                Alert($"{etypeResult.Message}", NotificationType.info, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                ViewBag.EntityTypes = null;
            }
            else
            {
                ViewBag.EntityTypes = etypeResult.Data;
            }


            var anchor = new EditAnchorViewModel();

            try
            {
                var result = await _anchorService.FindByIdInclusive(id, x => x.Include(p => p.EntityType).Include(w => w.Address).ThenInclude(f => f.Region).Include(q => q.Setting).Include(g => g.ContactPerson));

                if (!result.Success)
                {
                    Alert($"Error! {result.Message}", NotificationType.info, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                    return(View(anchor));
                }
                var anchor1 = new EditAnchorViewModel
                {
                    AnchorId                  = result.Data.Id,
                    AddressEmail              = result.Data.Address?.EmailAddress,
                    AddressPhone              = result.Data.Address?.PhoneNumber,
                    City                      = result.Data.Address.City,
                    ContactEmail              = result.Data.ContactPerson?.ContactEmail,
                    ContactPhone              = result.Data.ContactPerson?.ContactPhone,
                    Name                      = result.Data.Name,
                    DateOfRegistration        = result.Data.DateOfRegistration,
                    Description               = result.Data.Description,
                    FirstName                 = result.Data.ContactPerson.FirstName,
                    LastName                  = result.Data.ContactPerson.FirstName,
                    LicenceNumber             = result.Data.LicenceNumber,
                    PurchaseOrderAutoApproval = result.Data.Setting.PurchaseOrderAutoApproval,
                    SaleOrderAutoApproval     = result.Data.Setting.SaleOrderAutoApproval,
                    RegistrationNumber        = result.Data.RegistrationNumber,
                    SettingDescription        = result.Data.Setting?.Description,
                    SettingName               = result.Data.Setting?.Name,
                    Street                    = result.Data.Address?.Street,
                    EntityTypeId              = result.Data.EntityType.Id,
                    RegionId                  = result.Data.Address.Region.Id,
                    TierId                    = result.Data.TierId
                };
                return(View(anchor1));
            }
            catch (Exception ex)
            {
                Alert($"Error! {ex.Message}", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(View(anchor));
            }
        }