コード例 #1
0
        public async Task <IActionResult> AddClientGroup(string clientId, [FromBody] GroupApiModel groupApiModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(new UnprocessableEntityResult());
            }

            var group = groupApiModel.ToDomainModel();

            await this.clientGroupsRepository.AddGroup(clientId, group);

            return(new EntityCreatedResult());
        }
コード例 #2
0
        public IHttpActionResult Put(int id, [FromBody] GroupApiModel value)
        {
            try
            {
                if (id <= 0)
                {
                    return(BadRequest(Messages.ApiIllegalParameter));
                }

                using (DbContextTransaction tx =
                           dbContext.Database.BeginTransaction(System.Data.IsolationLevel.Serializable))
                {
                    value.Id = id;
                    GroupModel group = dbContext.GroupModels.Where(m => m.Id == value.Id).SingleOrDefault();
                    if (group == null)
                    {
                        tx.Rollback();
                        return(NotFound());
                    }

                    group.Code                        = value.Code;
                    group.Name                        = value.Name;
                    group.MakerModelId                = value.MakerModelId;
                    group.ContainerModelId            = value.ContainerModelId;
                    group.IsCapacity                  = value.IsCapacity;
                    group.ContainerCapacityBt20Dry    = value.ContainerCapacityBt20Dry;
                    group.ContainerCapacityBt20Reefer = value.ContainerCapacityBt20Reefer;
                    group.ContainerCapacityBt40Dry    = value.ContainerCapacityBt40Dry;
                    group.ContainerCapacityBt40Reefer = value.ContainerCapacityBt40Reefer;
                    group.Deleted                     = value.Deleted;

                    dbContext.Entry(group).State = EntityState.Modified;
                    if (dbContext.SaveChanges() == 0)
                    {
                        tx.Rollback();
                        return(BadRequest(ModelState.GetErrorsDelprefix("value")));
                    }

                    tx.Commit();
                    return(Ok(value));
                }
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
コード例 #3
0
        public static void create(GroupApiModel ViewModel)
        {
            var Entity = new Entities();

            //Tạo nhóm
            var _Nhom = new Nhom
            {
                Ten = ViewModel.name
            };

            //Set thông tin nhóm
            set(_Nhom, ViewModel, Entity);

            //Thêm nhóm
            Entity.Nhoms.Add(_Nhom);
            Entity.SaveChanges();
        }
コード例 #4
0
        public static bool update(int Id, GroupApiModel ViewModel)
        {
            Entities entities = new Entities();

            //Tìm nhóm có Id
            Nhom nhom = entities.Nhoms.Where(p => p.id == Id).First();

            if (nhom == null)
            {
                return(false);
            }

            set(nhom, ViewModel, entities);

            //Bắt đầu update
            entities.SaveChanges();
            return(true);
        }
コード例 #5
0
        public IHttpActionResult Post([FromBody] GroupApiModel value)
        {
            try
            {
                dbContext.Database.ExecuteSqlCommand(ContextResources.IncrementResetGroup);
                using (DbContextTransaction tx =
                           dbContext.Database.BeginTransaction(System.Data.IsolationLevel.Serializable))
                {
                    GroupModel group = dbContext.GroupModels.Where(x => x.Code == value.Code).SingleOrDefault();
                    if (group != null)
                    {
                        tx.Rollback();
                        return(Conflict());
                    }

                    group                             = new GroupModel();
                    group.Code                        = value.Code;
                    group.Name                        = value.Name;
                    group.MakerModelId                = value.MakerModelId;
                    group.ContainerModelId            = value.ContainerModelId;
                    group.IsCapacity                  = value.IsCapacity;
                    group.ContainerCapacityBt20Dry    = value.ContainerCapacityBt20Dry;
                    group.ContainerCapacityBt20Reefer = value.ContainerCapacityBt20Reefer;
                    group.ContainerCapacityBt40Dry    = value.ContainerCapacityBt40Dry;
                    group.ContainerCapacityBt40Reefer = value.ContainerCapacityBt40Reefer;
                    group.Deleted                     = value.Deleted;

                    dbContext.GroupModels.Add(group);
                    if (dbContext.SaveChanges() == 0)
                    {
                        tx.Rollback();
                        return(BadRequest(ModelState.GetErrorsDelprefix("value")));
                    }
                    dbContext.Database.ExecuteSqlCommand(ContextResources.IncrementResetGroup);
                    tx.Commit();
                    return(Created(Request.RequestUri + "/" + group.Id, group));
                }
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
コード例 #6
0
        // POST: api/Group
        public string Post(GroupApiModel ViewModel)
        {
            var Session = HttpContext.Current.Session;

            if (!Session.isAdminSession())
            {
                return("");
            }

            if (string.IsNullOrEmpty(ViewModel.name))
            {
                return(JsonConvert.
                       SerializeObject(new ResultViewModel(
                                           "Tên nhóm tài khoản không được bỏ trống",
                                           "Đã xảy ra lỗi trong quá trình tạo nhóm tài khoản")));
            }


            Group_DAO.create(ViewModel);
            return("");
        }
コード例 #7
0
        public static void set(Nhom _Nhom, GroupApiModel ViewModel, Entities Entity)
        {
            //Với mỗi user
            _Nhom.TaiKhoan =
                Entity.TaiKhoan.Where(p => ViewModel.usersId.Contains(p.id)).ToArray();

            //Với mỗi chi nhánh

            foreach (AffiliationPermisionModel AffiliationPermision in ViewModel.affiliationsWithPermision.OrEmptyIfNull())
            {
                NhomThuocChiNhanh nhomThuocChiNhanh = new NhomThuocChiNhanh();
                nhomThuocChiNhanh.Nhom       = _Nhom;
                nhomThuocChiNhanh.MaChiNhanh = AffiliationPermision.id;

                //Với mỗi down permision
                foreach (int permisionId in AffiliationPermision.downPermision.OrEmptyIfNull())
                {
                    QuyenTai_NhomThuocChiNhanh quyenTai = new QuyenTai_NhomThuocChiNhanh
                    {
                        Quyen = permisionId
                    };

                    nhomThuocChiNhanh.QuyenTai_NhomThuocChiNhanh.Add(quyenTai);
                }

                //Với mỗi search permision
                foreach (int permisionId in AffiliationPermision.searchPermision.OrEmptyIfNull())
                {
                    QuyenXem_NhomThuocChiNhanh quyenXem = new QuyenXem_NhomThuocChiNhanh
                    {
                        Quyen = permisionId
                    };

                    nhomThuocChiNhanh.QuyenXem_NhomThuocChiNhanh.Add(quyenXem);
                }

                _Nhom.NhomThuocChiNhanh.Add(nhomThuocChiNhanh);
            }
        }
コード例 #8
0
        public IHttpActionResult Get(int id, [FromUri] BaseApiParameterModel param)
        {
            try
            {
                if (id <= 0)
                {
                    return(BadRequest(Messages.ApiIllegalParameter));
                }

                GroupApiModel result = dbContext.GroupModels.Where(x => x.Id == id)
                                       .ProjectTo <GroupApiModel>().SingleOrDefault();
                if (result == null)
                {
                    return(NotFound());
                }

                return(Ok(result));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
コード例 #9
0
        public async Task <IActionResult> UpdateClientGroup(string clientId, string groupId, [FromBody] GroupApiModel groupApiModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(new UnprocessableEntityResult());
            }

            groupApiModel.Id = groupId;
            var group = groupApiModel.ToDomainModel();

            await this.clientGroupsRepository.Update(clientId, group);

            return(this.Ok());
        }