Exemplo n.º 1
0
        public Task Handle(CadastrarAreaCommand message, CancellationToken cancellationToken)
        {
            if (!message.IsValid())
            {
                NotifyValidationErrors(message);
                return(Task.CompletedTask);
            }

            var area = new Area(Guid.NewGuid(), message.Nome);

            if (_areaRepository.GetByNome(area.Nome) != null)
            {
                Bus.RaiseEvent(new DomainNotification(message.MessageType, "Já existe uma área com esse nome."));
                return(Task.CompletedTask);
            }

            _areaRepository.Add(area);

            if (Commit())
            {
                Bus.RaiseEvent(new AreaRegisteredEvent(area.Id, area.Nome));
                return(Task.CompletedTask);
            }

            return(Task.CompletedTask);
        }
Exemplo n.º 2
0
        // <summary>
        // Add /Update Area
        // </summary>
        public Area SaveArea(Area area)
        {
            Area dbVersion = areaRepository.Find(area.AreaId);

            //Code Duplication Check
            if (areaRepository.DoesAreaCodeExist(area))
            {
                throw new CaresException(Resources.GeographicalHierarchy.Area.AreaCodeDuplicationError);
            }

            if (dbVersion != null)
            {
                UpdateAreaPropertie(area, dbVersion);
                areaRepository.Update(dbVersion);
            }
            else
            {
                dbVersion = new Area();
                SetAreaProperties(area, dbVersion);
                areaRepository.Add(dbVersion);
            }
            areaRepository.SaveChanges();
            // To Load the proprties
            return(areaRepository.LoadAreaWithDetail(dbVersion.AreaId));
        }
Exemplo n.º 3
0
        public async Task <ActionResult> CreateArea(Area area)
        {
            if (ModelState.IsValid)
            {
                await areaRepository.Add(area);

                return(RedirectToAction("Index", "Area"));
            }
            return(View(area));
        }
Exemplo n.º 4
0
        public async Task <bool> Handle(CreateAreaCommand request, CancellationToken cancellationToken)
        {
            var area = new Area();

            area.AreaCod  = request.AreaCod;
            area.AreaName = request.AreaName;

            _writeRepository.Add(area);
            //_writeRepository.Save();

            return(await _writeRepository.SaveAsync(cancellationToken));
        }
Exemplo n.º 5
0
        public ActionResult Create(Area area)
        {
            if (ModelState.IsValid)
            {
                _areaRepository.Add(area);
                _areaRepository.Commit();

                return(RedirectToAction("Index"));
            }

            return(View(area));
        }
        public async Task <IActionResult> Create([FromBody] Area item)
        {
            if (item.AreaId == 0)
            {
                await _repository.Add(item);

                return(CreatedAtRoute("GetArea", new { Controller = "Area", id = item.AreaId }, item));
            }
            else
            {
                if (item.AreaId > 0)
                {
                    await _repository.Update(item);
                }
            }
            return(BadRequest());
        }
Exemplo n.º 7
0
        public void AreaRepository_Add()
        {
            Area areaTest = new Area
            {
                Name        = "Area test",
                AreaCode    = "A_UT",
                Description = "Add area unit test",
                LocationID  = 1
            };
            var actual = _areaRepository.Add(areaTest);

            _unitOfWork.Commit();

            var expected = "A_UT";

            Assert.IsNotNull(actual);
            Assert.AreEqual(expected, actual.AreaCode);
        }
Exemplo n.º 8
0
        public IActionResult Index(int floor)
        {
            MySqlConnection con = new MySqlConnection("host=sql7.freemysqlhosting.net;user=sql7323917;password=s1VSnVYe3w;database=sql7323917;");
            string          sql = " SELECT area_number, area_amount FROM Camera  ";
            MySqlCommand    cmd = new MySqlCommand(sql, con);

            con.Open();

            MySqlDataReader reader = cmd.ExecuteReader();

            Dictionary <string, string> values = new Dictionary <string, string>();

            while (reader.Read())
            {
                string area_number = reader.GetString(0);
                string area_amount = reader.GetString(1);
                values.Add(area_number, area_amount);
            }

            foreach (KeyValuePair <string, string> entry in values)
            {
                Area area = _areaRepo.GetByAreaNumber(entry.Key);
                if (area != null)
                {
                    area.Amount = Convert.ToInt32(entry.Value);
                    _areaRepo.Update(area);
                }
                else
                {
                    area = new Area(entry.Key, Convert.ToInt32(entry.Value));
                    _areaRepo.Add(area);
                }
            }
            con.Close();
            _areaRepo.SaveChanges();

            FloorPlanViewModel vm = new FloorPlanViewModel();

            vm.Dimensions = _dimRepo.GetAll().Where(dim => dim.Floor == floor).ToList();
            vm.Areas      = _areaRepo.GetAll();
            vm.FloorId    = floor;
            return(View(vm));
        }
Exemplo n.º 9
0
        public IActionResult Create([FromBody] AreaViewModel area)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Area _newArea = new Area {
                Name = area.Name
            };

            _areaRepository.Add(_newArea);
            _areaRepository.Commit();

            area = Mapper.Map <Area, AreaViewModel>(_newArea);

            CreatedAtRouteResult result = CreatedAtRoute("GetArea", new { controller = "Areas", id = area.Id }, area);

            return(result);
        }
Exemplo n.º 10
0
        public ActionResult Create(AreaModel areaModel)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.Areas = GetCurrentSelectableAreaItems();
                return(View(areaModel));
            }

            areaRepository.Add(viewModelToArea(areaModel));

            auditLogRepository.Add(
                AuditLogBuilder.Builder()
                .User(HttpContext.User.Identity.Name)
                .Added(typeof(Area), areaModel.Name)
                .With(new ChangeInfo().AddChange(() => areaModel.Name).ToJson())
                .Build());

            logger.Info("User '{0}' created area '{1}'.", Identity.Name, areaModel.Name);

            return(RedirectToAction("Index"));
        }
Exemplo n.º 11
0
 public AreaBaseDto AddArea(AreaBaseDto area)
 {
     area.Id = _areaRepository.Add(_mapper.Map <AreaBaseDto, Area>(area));
     return(area);
 }
Exemplo n.º 12
0
 public async Task <int> AddAreaAsync(Area Area)
 {
     return(await _areaRepo.Add(Area));
 }
Exemplo n.º 13
0
 public void Add(Area area)
 {
     _areaRepository.Add(area);
 }
Exemplo n.º 14
0
 public Area Add(Area obj)
 {
     return(_areaRepository.Add(obj));
 }
Exemplo n.º 15
0
        public async Task <int> AddSportListAsync(SportList sportList)
        {
            var savedNutritionList = await _sportListRepo.AddEntityAndGetId(sportList);

            SportDay sDay    = null;
            Area     aDay    = null;
            int      success = 0;

            for (int i = 1; i <= 7; i++)
            {
                sDay               = new SportDay();
                sDay.Name          = i + ".Gün";
                sDay.FKSportListId = savedNutritionList.Id;
                sDay               = await _sportDayRepository.AddEntityAndGetId(sDay);

                for (int j = 1; j <= 8; j++)
                {
                    aDay = new Area();
                    if (j == 1)
                    {
                        aDay.Name = "Göğüs";
                    }
                    else if (j == 2)
                    {
                        aDay.Name = "Sırt";
                    }
                    else if (j == 3)
                    {
                        aDay.Name = "Omuz";
                    }
                    else if (j == 4)
                    {
                        aDay.Name = "Ön Kol";
                    }
                    else if (j == 5)
                    {
                        aDay.Name = "Arka Kol";
                    }
                    else if (j == 6)
                    {
                        aDay.Name = "Bacak";
                    }
                    else if (j == 7)
                    {
                        aDay.Name = "Kardiyo";
                    }
                    else
                    {
                        aDay.Name = "Karın";
                    }

                    aDay.FKDayId = sDay.Id;
                    success      = await _areaRepository.Add(aDay);
                }
            }
            if (success > 0)
            {
                return(1);
            }
            return(0);
        }