Esempio n. 1
0
        public ResponseBase PatronIntroducerSet(PatronRequest request)
        {
            try
            {
                NullSafeCheck(request, "PatronRequest");
                NullSafeCheck(request.DTO, "DTO");

                if (request.DTO.ID <= 0)
                {
                    throw new CustomException(BAD_REQ_USER_MESSAGE, $"Patron ID {request.DTO.ID} is not valid");
                }
                if ((request.DTO.IntroducerID ?? 0) <= 0)
                {
                    throw new CustomException(BAD_REQ_USER_MESSAGE, $"IntroducerID {request.DTO.IntroducerID} is not valid");
                }

                using (var context = new CharityEntities())
                {
                    var patron = context.Patrons.FirstOrDefault(p => p.ID == request.DTO.ID);
                    patron.IntroducerID = request.DTO.IntroducerID;

                    context.SaveChanges();
                }

                return(new ResponseBase(true, 1));
            }
            catch (Exception ex)
            {
                LogHelper.Log(ex);
                return(ExceptionToBaseResponse(ex));
            }
        }
Esempio n. 2
0
        private int EntitySet <T, E>(T dto) where T : DTO.DTOBase
        {
            using (var context = new CharityEntities())
            {
                if (dto.ID == 0)
                {
                    dto.CreateDate = DateTime.Now;
                    dto.Active     = true;
                }
                else
                {
                    dto.ModifyDate = DateTime.Now;
                }

                E   entity = Map <T, E>(dto);
                var entry  = context.Entry(entity);
                entry.State = dto.ID == 0 ? System.Data.Entity.EntityState.Added : System.Data.Entity.EntityState.Modified;
                if (dto.ID > 0)
                {
                    entry.Property("CreateDate").IsModified = false;
                    entry.Property("CreateUser").IsModified = false;
                }
                context.SaveChanges();
                return((int)entry.Property("ID").OriginalValue);
            }
        }
Esempio n. 3
0
        private bool EntityDelete <T, E>(int id) where T : DTOBase
        {
            using (var context = new CharityEntities())
            {
                T dto = Activator.CreateInstance <T>();
                dto.ID         = id;
                dto.Active     = false;
                dto.ModifyDate = DateTime.Now;

                E entity = Map <T, E>(dto);

                var entry      = context.Entry(entity);
                var activeProp = entry.Property("Active");

                if (activeProp != null)
                {
                    entry.State = System.Data.Entity.EntityState.Modified;
                    foreach (var item in entity.GetType().GetProperties())
                    {
                        if (item.GetGetMethod().IsVirtual)
                        {
                            continue;
                        }
                        if (item.Name == "Active" || item.Name == "ModifyDate" || item.Name == "State" || item.Name == "ID")
                        {
                            continue;
                        }
                        var prop = entry.Property(item.Name);
                        if (prop != null)
                        {
                            prop.IsModified = false;
                        }
                    }
                }
                else
                {
                    entry.State = System.Data.Entity.EntityState.Deleted;
                }

                context.SaveChanges();
                return(true);
            }
        }
 public ResponseBase RequestResearch(RequestRequest request)
 {
     try
     {
         NullSafeCheck(request, "RequestRequest");
         NullSafeCheck(request.DTO, "RequestDTO");
         UserCheck(request, request.DTO);
         using (var context = new CharityEntities())
         {
             var entity = context.Requests.FirstOrDefault(r => r.ID == request.DTO.ID);
             entity.ResearchDate = DateTime.Now;
             context.SaveChanges();
         }
         return(new ResponseBase(true, 1));
     }
     catch (Exception ex)
     {
         return(ExceptionToBaseResponse(ex));
     }
 }