Example #1
0
        public override bool DeleteData(int id, out Notification notification)
        {
            notification      = new Notification();
            notification.Type = NotificationType.Success;

            try
            {
                using (var context = this.CreateContext())
                {
                    ClientPermission productionTeam = context.ClientPermission.FirstOrDefault(o => o.ClientPermissionID == id);

                    if (productionTeam == null)
                    {
                        notification.Type    = NotificationType.Error;
                        notification.Message = "Can not found data!";

                        return(false);
                    }

                    context.ClientPermission.Remove(productionTeam);
                    context.SaveChanges();
                }

                return(true);
            }
            catch (System.Exception ex)
            {
                notification.Type    = NotificationType.Error;
                notification.Message = ex.Message;

                return(false);
            }
        }
Example #2
0
 public void DTO2DB_ClientPermission(DTO.ClientPermissionDTO dto, ref ClientPermission db)
 {
     AutoMapper.Mapper.Map <DTO.ClientPermissionDTO, ClientPermission>(dto, db);
 }
Example #3
0
        public override bool UpdateData(int userId, int id, ref object dtoItem, out Notification notification)
        {
            DTO.ClientPermissionDTO clientPermissionDTO = ((JObject)dtoItem).ToObject <DTO.ClientPermissionDTO>();
            notification = new Notification()
            {
                Type = NotificationType.Success
            };

            try
            {
                using (var context = this.CreateContext())
                {
                    ClientPermission clientPermission = new ClientPermission();

                    if (id == 0)
                    {
                        context.ClientPermission.Add(clientPermission);
                    }

                    if (id > 0)
                    {
                        clientPermission = context.ClientPermission.FirstOrDefault(o => o.ClientPermissionID == id);

                        if (clientPermission == null)
                        {
                            notification.Message = "Can not found data!";
                            return(false);
                        }
                    }
                    clientPermission.ClientID    = clientPermissionDTO.ClientID;
                    clientPermission.Remark      = clientPermissionDTO.Remark;
                    clientPermission.UpdatedBy   = userId;
                    clientPermission.UpdatedDate = System.DateTime.Now;
                    List <int> dbClientPermissionDelete = clientPermission.ClientPermissionDetail.Select(y => y.ClientPermissionDetailID).Where(x => !clientPermissionDTO.ClientPermissionDetailDTOs.Select(z => z.ClientPermissionDetailID).Contains(x)).ToList();
                    foreach (DTO.ClientPermissionDetailDTO item in clientPermissionDTO.ClientPermissionDetailDTOs)
                    {
                        if (item.ClientPermissionDetailID < 0)
                        {
                            clientPermission.ClientPermissionDetail.Add(converter.DTO2DB_ClientPermissionDetail(item));
                        }
                        else
                        {
                            ClientPermissionDetail detail = clientPermission.ClientPermissionDetail.Where(x => x.ClientPermissionDetailID == item.ClientPermissionDetailID).FirstOrDefault();
                            detail.UserId   = item.UserID;
                            detail.ModuleID = item.ModuleID;
                        }
                    }
                    foreach (int iddelete in dbClientPermissionDelete)
                    {
                        ClientPermissionDetail itemdelete = clientPermission.ClientPermissionDetail.Where(x => x.ClientPermissionDetailID == iddelete).FirstOrDefault();
                        if (itemdelete != null)
                        {
                            clientPermission.ClientPermissionDetail.Remove(itemdelete);
                        }
                    }
                    context.SaveChanges();
                    dtoItem = this.GetData(clientPermission.ClientPermissionID, out notification);
                }

                return(true);
            }
            catch (System.Exception ex)
            {
                notification.Type    = NotificationType.Error;
                notification.Message = ex.Message;

                return(false);
            }
        }