コード例 #1
0
        public async Task <IActionResult> PutInvoice(int id, Invoice invoice)
        {
            if (id != invoice.InvoiceId)
            {
                return(BadRequest());
            }

            _context.Entry(invoice).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!InvoiceExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #2
0
        public async Task <EquipmentResponse> AddEquipment(EquipmentCreateRequest values)
        {
            EquipmentResponse _response = new EquipmentResponse();

            try
            {
                EntityEntry <EquipmentEntity> result = await _context.Equipment.AddAsync(new EquipmentEntity
                {
                    EquipmentGuid = Guid.NewGuid().ToString(),
                    ClinicGuid    = values.ClinicGuid,
                    Name          = values.Name,
                    Quantity      = values.Quantity,
                    UnitPrice     = values.UnitPrice,
                    RateOfUse     = values.RateOfUse,
                    DateofSupply  = values.DateofSupply,
                    Created       = DateTime.Now.ToUniversalTime(),
                    Updated       = DateTime.Now.ToUniversalTime(),
                    IsDeleted     = false,
                });

                if (result.Entity.Validate(validationContext: null).Count() == 0)
                {
                    await _context.SaveChangesAsync();

                    _response.Code         = "E000";
                    _response.Message      = _localizer["success"];
                    _response.DataCount    = 1;
                    _response.ResponseDate = DateTime.Now.ToUniversalTime();
                    _response.Results.Add(result.Entity);
                }
                else
                {
                    _response.Code    = "E001";
                    _response.Message = _localizer["check_values"];
                    foreach (System.ComponentModel.DataAnnotations.ValidationResult item in result.Entity.Validate(validationContext: null).ToList())
                    {
                        _response.Message += item.ErrorMessage + " ";
                    }
                    _response.DataCount    = 0;
                    _response.ResponseDate = DateTime.Now.ToUniversalTime();
                    _response.Results.Add(result.Entity);
                }
            }
            catch (Exception ex)
            {
                _response.Code         = "E999";
                _response.Message      = ex.Message;
                _response.DataCount    = 0;
                _response.ResponseDate = DateTime.Now.ToUniversalTime();
                _response.Results      = null;
            }
            return(_response);
        }
コード例 #3
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Project).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProjectExists(Project.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
コード例 #4
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(MaintenanceContent).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MaintenanceContentExists(MaintenanceContent.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            Platforms = new SelectList((from i in _context.Instruments
                                        select i.Platform).Distinct());
            return(RedirectToPage("./Index"));
        }
コード例 #5
0
        public async Task <IActionResult> OnPostAsync(int id)
        {
            Project = await _context.Projects.FindAsync(id);

            if (Project != null)
            {
                _context.Projects.Remove(Project);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
コード例 #6
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Components.Add(Component);
            await _context.SaveChangesAsync();

            return(RedirectToPage("../Instruments/Details", new { id = Component.InstrumentID }));
        }
コード例 #7
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.MaintenanceContents.Add(MaintenanceContent);

            await _context.SaveChangesAsync();

            Platforms = new SelectList((from i in _context.Instruments
                                        select i.Platform).Distinct());

            return(RedirectToPage("./Index"));
        }
コード例 #8
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            MaintenanceContent = await _context.MaintenanceContents.FindAsync(id);

            if (MaintenanceContent != null)
            {
                _context.MaintenanceContents.Remove(MaintenanceContent);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
コード例 #9
0
        public async Task CreateRequestForCommandAsync <T>(Guid id)
        {
            var exists = await ExistAsync(id);

            var request = exists ?
                          throw new EquipmentDomainException($"Request with {id} already exists") :
                                new ClientRequest()
                                {
                                    Id   = id,
                                    Name = typeof(T).Name,
                                    Time = DateTime.UtcNow
                                };

            _context.Add(request);

            await _context.SaveChangesAsync();
        }
コード例 #10
0
        public async Task <Invoice> SaveCart(Cart cart)
        {
            var customer = await _context.Customers.FindAsync(cart.Client.CustomerId);

            Invoice invoice = new Invoice {
                Customer = customer, CustomerId = customer.CustomerId, Title = $"Invoice {customer.CustomerName}"
            };

            var items = cart.CartItem
                        .Select(item => new LineItem {
                EquipmentId = item.EquipmentId, DaysRent = item.DaysRent
            })
                        .Where(item => item.DaysRent > 0)
                        .ToList();

            invoice.OrderItem = items;
            await _context.Invoice.AddAsync(invoice);

            await _context.SaveChangesAsync();

            return(invoice);
        }