Beispiel #1
0
        public override bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification)
        {
            DTO.ComplianceCertificateTypeDTO ComplianceCertificateTypeDTO = ((JObject)dtoItem).ToObject <DTO.ComplianceCertificateTypeDTO>();

            notification = new Notification {
                Type = NotificationType.Success
            };

            try
            {
                using (var context = CreateContext())
                {
                    ComplianceCertificateType complianceCertificateType = new ComplianceCertificateType();

                    if (id == 0)
                    {
                        context.ComplianceCertificateType.Add(complianceCertificateType);
                    }

                    if (id > 0)
                    {
                        complianceCertificateType = context.ComplianceCertificateType.FirstOrDefault(o => o.ComplianceCertificateTypeID == id);

                        if (complianceCertificateType == null)
                        {
                            notification = new Notification {
                                Type = NotificationType.Error, Message = "Can't Find Data"
                            };
                            return(false);
                        }
                    }

                    this.converter.DTO2DB_ComplianceCertificateType(ComplianceCertificateTypeDTO, ref complianceCertificateType);
                    context.SaveChanges();

                    dtoItem = this.GetData(complianceCertificateType.ComplianceCertificateTypeID, out notification);
                }
                return(true);
            }
            catch (Exception ex)
            {
                notification = new Notification {
                    Type = NotificationType.Error, Message = ex.Message
                };
                return(false);
            }
        }
Beispiel #2
0
        public override bool DeleteData(int id, out Library.DTO.Notification notification)
        {
            notification = new Notification {
                Type = NotificationType.Success
            };

            try
            {
                using (var Context = CreateContext())
                {
                    ComplianceCertificateType unit = Context.ComplianceCertificateType.FirstOrDefault(o => o.ComplianceCertificateTypeID == id);

                    if (unit == null)
                    {
                        notification = new Notification {
                            Type = NotificationType.Error, Message = "Can't Find Data"
                        };
                        return(false);
                    }
                    var item = Context.ComplianceCertificateTypeMng_ComplianceCertificateTypeCheck_View.Where(o => o.ComplianceCertificateTypeID == id).FirstOrDefault();
                    //CheckPermission
                    if (item.isUsed.Value == true)
                    {
                        throw new Exception("You can't delete because it's used");
                    }

                    Context.ComplianceCertificateType.Remove(unit);
                    Context.SaveChanges();
                }
                return(true);
            }
            catch (Exception ex)
            {
                notification = new Notification()
                {
                    Type = NotificationType.Error, Message = ex.Message
                };
                return(false);
            }
        }
Beispiel #3
0
 public void DTO2DB_ComplianceCertificateType(DTO.ComplianceCertificateTypeDTO dto, ref ComplianceCertificateType db)
 {
     AutoMapper.Mapper.Map <DTO.ComplianceCertificateTypeDTO, ComplianceCertificateType>(dto, db);
 }