コード例 #1
0
        public async Task CreateAsync(ContainerSaveModel containerModel)
        {
            containerModel.Number = GetNextNumber();
            var container = new Container();

            containerModel.ApplyToEntity(container, dataStore, positionService);

            await dataStore.SaveAsync(container);
        }
コード例 #2
0
        public void Create(ContainerSaveModel containerModel)
        {
            containerModel.Number = GetNextNumber();
            var container = new Container();

            containerModel.ApplyToEntity(container, dataStore, positionService);

            dataStore.Save(container);
        }
コード例 #3
0
        public async Task UpdateAsync(long id, ContainerSaveModel containerModel)
        {
            var container = dataStore.Get <Container>(id);

            if (container == null)
            {
                throw new EntityNotFoundException($"Запись типа {typeof(Container).Name} c идентификатором {id} не существует");
            }

            containerModel.ApplyToEntity(container, dataStore, positionService);

            await dataStore.SaveChangesAsync();
        }
コード例 #4
0
        /// <summary>
        /// Частичное представление - открытие окна создания
        /// </summary>
        public ActionResult Create()
        {
            var model = new ContainerSaveModel();

            var containerStatuses = Enum.GetValues(typeof(ContainerStatus))
                                    .Cast <ContainerStatus>()
                                    .Select(x => new SelectListItem {
                Value = x.ToString(), Text = x.GetDescription()
            })
                                    .ToList();

            var containerTypes = _containerTypeService.GetAllContainerTypeModels(null)
                                 .Select(x => new SelectListItem {
                Value = x.Id.ToString(), Text = x.Name
            })
                                 .ToList();

            var editWindowModel = new ContainerEditWindowModel <ContainerSaveModel>(model, containerStatuses, containerTypes);

            return(PartialView("Partial/Create", editWindowModel));
        }
コード例 #5
0
        public int SaveContainer(ContainerSaveModel containerSaveModel)
        {
            try
            {
                using (var dbContext = new DiplomaDBContext())
                {
                    var locationId  = dbContext.Location.Count() + 1;
                    var containerId = dbContext.Container.Count() + 1;

                    var location = new Location
                    {
                        Id        = locationId,
                        Latitude  = containerSaveModel.location.lat,
                        Longitude = containerSaveModel.location.lng
                    };

                    var container = new Container
                    {
                        Id         = containerId,
                        Code       = containerSaveModel.code,
                        LocationId = locationId,
                        Full       = false,
                        RegionId   = containerSaveModel.region
                    };

                    dbContext.Location.Add(location);
                    dbContext.Container.Add(container);
                    dbContext.SaveChanges();

                    return(1);
                }
            }
            catch
            {
                return(0);
            }
        }