public EditRecordPage(string tableName, object id)
 {
     this.tableName = tableName;
     this.id        = id;
     InitializeComponent();
     BindingContext = viewModel = new EditRecordViewModel(tableName, id, App.Database);
 }
示例#2
0
        public async Task <RecordListViewModel> EditRecord(EditRecordViewModel model, string agentId)
        {
            if (!await IsAgentExisting(agentId))
            {
                throw new ArgumentException("Агентът, не е намерен!");
            }

            var record = await dbContext.ContactsDiary
                         .FirstOrDefaultAsync(c => c.Id == model.Id)
                         ?? throw new ContentNotFoundException("Не е намерен записът!");

            record.PhoneNumber           = model.PhoneNumber;
            record.Name                  = model.Name;
            record.Address               = model.Address;
            record.CityDistrict          = model.CityDistrict;
            record.CityId                = model.CityId;
            record.AdditionalDescription = model.AdditionalDescription;
            record.ContactedPersonTypeId = model.ContactedPersonTypeId;
            record.DealTypeId            = model.DealTypeId;
            record.PropertySource        = model.PropertySource;
            record.PropertyTypeId        = model.PropertyTypeId;
            record.NegotiationStateId    = model.NegotiationStateId;

            await dbContext.SaveChangesAsync();

            return(await dbContext.ContactsDiary
                   .Include(r => r.Agent)
                   .Include(r => r.NegotiationState)
                   .Include(r => r.ContactedPersonType)
                   .Include(r => r.DealType)
                   .Include(r => r.PropertyType)
                   .Where(c => c.Id == record.Id).Select(r => new RecordListViewModel
            {
                Id = r.Id,
                CreatedOn = r.CreatedOn,
                PhoneNumber = r.PhoneNumber,
                Name = r.Name,
                CityId = r.CityId,
                CityName = r.City.CityName,
                CityDistrict = r.CityDistrict,
                Address = r.Address,
                PropertySource = r.PropertySource,
                AdditionalDescription = r.AdditionalDescription,
                ContactedPersonTypeId = r.ContactedPersonTypeId,
                ContactedPersonType = r.ContactedPersonType.ContactedPersonType,
                DealTypeId = r.DealTypeId,
                DealType = r.DealType.DealType,
                PropertyTypeId = r.PropertyTypeId,
                PropertyType = r.PropertyType.PropertyTypeName,
                NegotiationStateId = r.NegotiationStateId,
                NegotiationState = r.NegotiationState.State,
                RecordColor = r.NegotiationState.Color,
                AgentId = r.AgentId,
                AgentName = r.Agent.FirstName + " " + r.Agent.LastName
            })
                   .FirstOrDefaultAsync());
        }
        public async Task <ActionResult> Edit(EditRecordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(ModelState.ToDictionary()));
            }

            var agentId = User.Identity.GetUserId();
            var record  = await _contactsDiaryServices.EditRecord(model, agentId);

            return(Json(record));
        }
示例#4
0
        public async Task <IActionResult> Edit(string id, int walletId)
        {
            try
            {
                var user = await this.userManager.GetUserAsync(this.User);

                if (!await this.recordsService.IsUserOwnRecordAsync(user.Id, id))
                {
                    return(this.Redirect($"/Home/Error?message={GlobalConstants.NoPermissionForViewOrEditRecord}"));
                }

                var recordDto = await this.recordsService.GetRecordWithAllCategories(id, walletId);

                EditRecordViewModel model = new EditRecordViewModel()
                {
                    Id          = recordDto.Id,
                    Description = recordDto.Description,
                    ModifiedOn  = recordDto.ModifiedOn,
                    CreatedOn   = recordDto.CreatedOn,
                    Type        = Enum.Parse <RecordTypeInputModel>(recordDto.Type.ToString()),
                    WalletId    = walletId,
                    Amount      = recordDto.Amount,
                    OldAmount   = 0,
                    WalletName  = recordDto.WalletName,
                    CategoryId  = recordDto.CategoryId,
                    Categories  = recordDto.Categories.Select(c => new CategoryNameIdViewModel
                    {
                        Id         = c.Id,
                        Name       = c.Name,
                        WalletName = c.WalletName,
                    })
                                  .ToList(),
                };

                return(this.View(model));
            }
            catch (Exception ex)
            {
                return(this.Redirect($"/Home/Error?message={ex.Message}"));
            }
        }
示例#5
0
        public ActionResult Edit(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Models.AccountBook accountBook = _AccountBookSvc.GetSingle(id.Value, User.Identity.Name);
            if (accountBook == null)
            {
                return(HttpNotFound());
            }

            var result = new EditRecordViewModel
            {
                Id       = accountBook.Id,
                Date     = accountBook.Date,
                Category = (BookType)accountBook.Category,
                Remark   = accountBook.Remark,
                Amount   = accountBook.Amount
            };

            return(View(result));
        }