private ActionResponse Add(TDto obj, Guid?userId = null)
 {
     try
     {
         ctx = Activator.CreateInstance <TContext>();
         var model = Mapper.Map <TDao>(obj);
         model.Id            = Guid.NewGuid();
         model.CreatedDate   = DateTime.UtcNow.AddHours(4);
         model.CreatedUserId = userId;
         model.ModifiedDate  = null;
         model.SetVersion(1);
         using (var transaction = ctx.Database.BeginTransaction())
         {
             if (obj.Id == default(Guid))
             {
                 ctx.Set <TDao>().Add(model);
             }
             var result = ctx.SaveChanges();
             transaction.Commit();
             obj.Id = model.Id;
             return(ActionResponse.Succeed());
         }
     }
     catch (Exception ex)
     {
         return(ActionResponse.Failure(ex.Message));
     }
 }
Esempio n. 2
0
        public static ActionResponse OutcomeAdd(DS_Outcome dS_Outcome)
        {
            string Id = Convert.ToInt32(dS_Outcome.DS_StockID.Value) + "" + Convert.ToInt32(dS_Outcome.ID);

            dS_Outcome.ID = Convert.ToDecimal(Id);

            foreach (var item in dS_Outcome.DS_OutcomeItems)
            {
                string Idd = Convert.ToInt32(dS_Outcome.DS_StockID.Value) + "" + Convert.ToInt32(item.ID);
                item.ID           = Convert.ToDecimal(Idd);
                item.DS_OutcomeID = Convert.ToDecimal(Id);
                item.QualityID    = Convert.ToDecimal(5);
            }

            try
            {
                var ctx   = new MainDataContext();
                var model = Mapper.Map <Entity.DS_Outcome>(dS_Outcome);
                using (var transaction = ctx.Database.BeginTransaction())
                {
                    ctx.Set <Entity.DS_Outcome>().Add(model);
                    var result = ctx.SaveChanges();
                    transaction.Commit();
                    _logger.Info($"Save({string.Join(",", dS_Outcome.ID)})");
                    return(ActionResponse.Succeed());
                }
            }
            catch (Exception ex)
            {
                _logger.Error($"Save({string.Join(",", dS_Outcome.ID)}), Exception: {ex}");
                return(ActionResponse.Failure(ex.Message));
            }
        }
 private ActionResponse Update(TDto obj, Guid?userId = null)
 {
     try
     {
         ctx = Activator.CreateInstance <TContext>();
         var model = Mapper.Map <TDao>(obj);
         using (var transaction = ctx.Database.BeginTransaction())
         {
             var dbModel = ctx.Set <TDao>().FirstOrDefault(x => x.Id == model.Id);
             dbModel.ModifiedUserId = userId;
             dbModel.ModifiedDate   = DateTime.UtcNow.AddHours(4);
             var version = dbModel.Version + 1;
             model.SetVersion(version);
             var entry = ctx.Entry(dbModel);
             entry.CurrentValues.SetValues(model);
             entry.Property(e => e.CreatedDate).IsModified   = false;
             entry.Property(e => e.CreatedUserId).IsModified = false;
             ctx.SaveChanges();
             transaction.Commit();
             obj.Id = model.Id;
             return(ActionResponse.Succeed());
         }
     }
     catch (Exception ex)
     {
         return(ActionResponse.Failure(ex.Message));
     }
 }
Esempio n. 4
0
        public static ActionResponse IncomePriceSimpleItemItemAdd(DS_IncomePriseSimpleItemItems dS_IncomePriseSimpleItemItems, decimal stockId, decimal incomePriceItemId)
        {
            string Id = Convert.ToInt32(stockId) + "" + Convert.ToInt32(dS_IncomePriseSimpleItemItems.ID);

            dS_IncomePriseSimpleItemItems.ID       = Convert.ToDecimal(Id);
            dS_IncomePriseSimpleItemItems.IdParent = incomePriceItemId;

            try
            {
                var ctx   = new MainDataContext();
                var model = Mapper.Map <Entity.DS_IncomePriseSimpleItemItems>(dS_IncomePriseSimpleItemItems);
                using (var transaction = ctx.Database.BeginTransaction())
                {
                    ctx.Set <Entity.DS_IncomePriseSimpleItemItems>().Add(model);
                    var result = ctx.SaveChanges();
                    transaction.Commit();
                    _logger.Info($"Save({string.Join(",", dS_IncomePriseSimpleItemItems.ID)})");
                    return(ActionResponse.Succeed());
                }
            }
            catch (Exception ex)
            {
                _logger.Error($"Save({string.Join(",", dS_IncomePriseSimpleItemItems.ID)}), Exception: {ex}");
                return(ActionResponse.Failure(ex.Message));
            }
        }
Esempio n. 5
0
 public ActionResponse <IQueryable <UserDto> > GetAll(params Enums.Status[] statuses)
 {
     try
     {
         var users = UserManager.Users.ProjectTo <UserDto>(Mapper.Configuration);
         return(ActionResponse <IQueryable <UserDto> > .Succeed(users));
     }
     catch (Exception exc)
     {
         return(ActionResponse <IQueryable <UserDto> > .Failure(exc.Message));
     }
 }
 public ActionResponse <IQueryable <RoleDto> > GetAll(params Enums.Status[] statuses)
 {
     try
     {
         var roles = _roleManager.Roles.ProjectTo <RoleDto>(Mapper.Configuration);
         return(ActionResponse <IQueryable <RoleDto> > .Succeed(roles));
     }
     catch (Exception exc)
     {
         return(ActionResponse <IQueryable <RoleDto> > .Failure(exc.Message));
     }
 }
 public ActionResponse <RoleDto> GetById(Guid id)
 {
     try
     {
         var user = _roleManager.FindById(id);
         var dto  = Mapper.Map <RoleDto>(user);
         return(ActionResponse <RoleDto> .Succeed(dto));
     }
     catch (Exception exc)
     {
         return(ActionResponse <RoleDto> .Failure(exc.Message));
     }
 }
 public virtual ActionResponse <TDto> GetById(Guid id)
 {
     try
     {
         ctx = Activator.CreateInstance <TContext>();
         var dao = ctx.Set <TDao>().FirstOrDefault(e => e.Id == id);
         var dto = Mapper.Map <TDto>(dao);
         return(ActionResponse <TDto> .Succeed(dto));
     }
     catch (Exception ex)
     {
         return(ActionResponse <TDto> .Failure(ex.Message));
     }
 }
 public virtual ActionResponse <IQueryable <TDto> > GetAll(params Enums.Status[] statuses)
 {
     try
     {
         ctx = Activator.CreateInstance <TContext>();
         var entities = ctx.Set <TDao>()
                        .Where(e => statuses.Count() == 0 || statuses.Contains(e.Status))
                        .ProjectTo <TDto>(Mapper.Configuration);
         return(ActionResponse <IQueryable <TDto> > .Succeed(entities));
     }
     catch (Exception ex)
     {
         return(ActionResponse <IQueryable <TDto> > .Failure(ex.Message));
     }
 }
        public ActionResponse <GenericAnnouncementDto> GetById(Guid id, params Enums.Status[] statuses)
        {
            try
            {
                var ctx = new MainDataContext();

                var dao = ctx.Set <GenericAnnouncementDao>().FirstOrDefault(e => e.Id == id);
                var dto = ToDTO(dao);
                return(ActionResponse <GenericAnnouncementDto> .Succeed(dto));
            }
            catch (Exception ex)
            {
                return(ActionResponse <GenericAnnouncementDto> .Failure(ex.Message));
            }
        }
 public override ActionResponse <IQueryable <GenericAnnouncementDto> > GetAll(params Enums.Status[] statuses)
 {
     try
     {
         var ctx = new MainDataContext();
         //40
         const string query    = "SELECT * FROM dbo.RANDOM_ANNOUNCEMENTS ORDER BY NEWID()";
         var          entities = ctx.Database.SqlQuery <GenericAnnouncementDao>(query).ToArray();
         var          result   = entities.Select(ToDTO).AsQueryable();
         return(ActionResponse <IQueryable <GenericAnnouncementDto> > .Succeed(result));
     }
     catch (Exception ex)
     {
         return(ActionResponse <IQueryable <GenericAnnouncementDto> > .Failure(ex.Message));
     }
 }
Esempio n. 12
0
 public ActionResponse Remove(Guid id, Guid?userId = null)
 {
     try
     {
         ctx = Activator.CreateInstance <TContext>();
         var data = ctx.Set <TDao>().Find(id);
         data.Status           = Status.Deleted;
         ctx.Entry(data).State = EntityState.Modified;
         var result = ctx.SaveChanges();
         return(ActionResponse.Succeed());
     }
     catch (Exception ex)
     {
         return(ActionResponse.Failure(ex.Message));
     }
 }
        public ActionResponse <IQueryable <GenericAnnouncementDto> > GetAll_Old(params Enums.Status[] statuses)
        {
            try
            {
                var ctx = new MainDataContext();

                var entities = ctx.Set <GenericAnnouncementDao>()
                               .Where(e => statuses.Count() == 0 || statuses.Contains(e.Status));
                var result = entities.Select(ToDTO).AsQueryable();
                return(ActionResponse <IQueryable <GenericAnnouncementDto> > .Succeed(result));
            }
            catch (Exception ex)
            {
                return(ActionResponse <IQueryable <GenericAnnouncementDto> > .Failure(ex.Message));
            }
        }
Esempio n. 14
0
        public static ActionResponse IncomePriceAdd(DS_IncomePrice dS_IncomePrice)
        {
            //string Id = 7 + "" + Convert.ToInt32(dS_IncomePrice.ID);
            int Id = Convert.ToInt32(dS_IncomePrice.ID);

            dS_IncomePrice.ID                = Id;
            dS_IncomePrice.StatusID          = 20174;
            dS_IncomePrice.OwnerID           = 12;
            dS_IncomePrice.BranchID          = 1;
            dS_IncomePrice.CurrencyID        = 6;
            dS_IncomePrice.CustomerID        = 38375;
            dS_IncomePrice.ExternalDocNumber = Id.ToString();
            dS_IncomePrice.PhysicalPersonID  = 38375;
            dS_IncomePrice.DS_StockID        = 7;
            dS_IncomePrice.RefIncomeTypeID   = 1;
            dS_IncomePrice.DsPaymentTypeID   = 1;


            foreach (var item in dS_IncomePrice.DS_IncomePriceItems)
            {
                string Idd = Convert.ToInt32(dS_IncomePrice.DS_StockID) + "" + Convert.ToInt32(item.ID);
                item.ID = Convert.ToDecimal(Idd);
                item.DS_IncomePriceID = Convert.ToDecimal(dS_IncomePrice.ID);
                //item.Quantity = 1;
                item.Price = 1;
                item.VatID = 3;
            }

            try
            {
                var ctx = new DataContext();
                //var model = Mapper.Map<ERP.WebApi.Entity.DS_IncomePrice>(dS_IncomePrice);
                using (var transaction = ctx.Database.BeginTransaction())
                {
                    ctx.Set <DS_IncomePrice>().Add(dS_IncomePrice);
                    var result = ctx.SaveChanges();
                    transaction.Commit();
                    _logger.Info($"Save({string.Join(",", dS_IncomePrice)})");
                    return(ActionResponse.Succeed());
                }
            }
            catch (Exception ex)
            {
                _logger.Error($"Save({string.Join(",", dS_IncomePrice)}), Exception: {ex.Message}");
                return(ActionResponse.Failure(ex.Message));
            }
        }
        public ActionResponse <IQueryable <Tuple <string, int> > > GetTopCities(params Enums.Status[] statuses)
        {
            try
            {
                ctx = Activator.CreateInstance <MainDataContext>();
                var data = ctx.Announcements.GroupBy(e => e.City.Name)
                           .Select(e => new { name = e.Key, count = e.Count() }).ToList()
                           .Select(e => Tuple.Create <string, int>(e.name, e.count))
                           .Where(e => e.Item2 > 4).AsQueryable();

                return(ActionResponse <IQueryable <Tuple <string, int> > > .Succeed(data));
            }
            catch (Exception ex)
            {
                return(ActionResponse <IQueryable <Tuple <string, int> > > .Failure(ex.Message));
            }
        }
Esempio n. 16
0
        public ActionResponse Remove(Guid id, Guid?userId = null)
        {
            try
            {
                var role = _roleManager.FindById(id);
                if (role == null)
                {
                    return(ActionResponse.Failure($"Role not found for id={id.ToString()}"));
                }
                _roleManager.Delete(role);
                return(ActionResponse.Succeed());
            }

            catch (Exception exc)
            {
                return(ActionResponse <RoleDto> .Failure(exc.Message));
            }
        }
Esempio n. 17
0
        public ActionResponse Remove(Guid id)
        {
            try
            {
                var user = _userManager.FindById(id);
                if (user == null)
                {
                    return(ActionResponse.Failure($"User not found for id={id.ToString()}"));
                }
                _userManager.Delete(user);
                return(ActionResponse.Succeed());
            }

            catch (Exception exc)
            {
                return(ActionResponse <UserDto> .Failure(exc.Message));
            }
        }
 public ActionResponse IncViewsCount(Guid id)
 {
     try
     {
         ctx = Activator.CreateInstance <MainDataContext>();
         var entity = ctx.Announcements.FirstOrDefault(e => e.Id == id);
         if (entity == null)
         {
             return(ActionResponse.Failure(UI.NotFound));
         }
         entity.ViewsCount += 1;
         ctx.Entry <AnnouncementDao>(entity).State = EntityState.Modified;
         ctx.SaveChanges();
         return(ActionResponse.Succeed());
     }
     catch (Exception ex)
     {
         return(ActionResponse.Failure(ex.Message));
     }
 }
 public ActionResponse DecUsedAnnouncementCount(Guid id)
 {
     try
     {
         ctx = Activator.CreateInstance <MainDataContext>();
         var entity = ctx.PricePlanHistories.FirstOrDefault(e => e.CustomerId == id);
         if (entity == null)
         {
             return(ActionResponse.Failure(UI.NotFound));
         }
         entity.UsedAnnouncementCount -= 1;
         ctx.Entry <PricePlanHistoryDao>(entity).State = EntityState.Modified;
         ctx.SaveChanges();
         return(ActionResponse.Succeed());
     }
     catch (Exception ex)
     {
         return(ActionResponse.Failure(ex.Message));
     }
 }
        public ActionResponse <int> SearchPagerSortByCount(SearchDto search, params Enums.Status[] statuses)
        {
            try
            {
                var ctx = new MainDataContext();

                var entities = ctx.Set <GenericAnnouncementDao>()
                               .Where(e => statuses.Count() == 0 || statuses.Contains(e.Status));
                var result = entities.Count();
                if (entities != null)
                {
                    List <string> citiNames = new List <string>();
                    //if (search.Regions.HasValue && !search.Departaments.HasValue)
                    //{

                    //    var departaments = ctx.RegionDepartaments.Where(x => x.RegionId == search.Regions.Value).ToList();
                    //    foreach (var departament in departaments)
                    //    {
                    //        var cities = ctx.DepartamentCities.Where(x => x.DepartamentId == departament.DepartamentId).ToList();
                    //        foreach (var city in cities)
                    //        {
                    //            var citiesname = ctx.Cities.Where(x => x.Id == city.CityId);
                    //                citiNames.AddRange(citiesname.Select(c => c.Name).ToList());
                    //        }
                    //    }
                    //    entities = entities.Where(x => citiNames.Contains(x.City));
                    //}
                    if (search.Departaments.HasValue)
                    {
                        var cities = ctx.DepartamentCities.Where(x => x.DepartamentId == search.Departaments.Value).ToList();
                        foreach (var city in cities)
                        {
                            var citiesname = ctx.Cities.Where(x => x.Id == city.CityId);
                            citiNames.AddRange(citiesname.Select(c => c.Name).ToList());
                        }
                        entities = entities.Where(x => citiNames.Contains(x.City));
                    }

                    if (search.Cities != null || search.CityName != null)
                    {
                        entities = entities.Where(x => search.CityName.Contains(x.City));
                    }
                    if (search.AnnouncementAdditionId != null)
                    {
                        entities = entities
                                   .Where(x => x.AnnouncementAddition.Contains(search.AnnouncementAdditionId));
                    }
                    if (search.announcementtype.HasValue)
                    {
                        entities = entities.Where(x => x.AnnouncementTypeId == search.announcementtype);
                    }
                    if (search.PropertyTypes.HasValue)
                    {
                        entities = entities.Where(x => x.PropertyTypeId == search.PropertyTypes);
                    }
                    if (search.minprice.HasValue)
                    {
                        entities = entities.Where(e => e.PriceDouble >= search.minprice.Value);
                    }
                    if (search.maxprice.HasValue)
                    {
                        entities = entities.Where(e => e.PriceDouble <= search.maxprice.Value);
                    }
                    if (search.minarea.HasValue)
                    {
                        entities = entities.Where(e => e.Area >= search.minarea.Value);
                    }
                    if (search.maxarea.HasValue)
                    {
                        entities = entities.Where(e => e.Area <= search.maxarea.Value);
                    }
                    if (search.minroomcount.HasValue)
                    {
                        entities = entities.Where(e => e.RoomCount >= search.minroomcount.Value);
                    }
                    if (search.maxroomcount.HasValue)
                    {
                        entities = entities.Where(e => e.RoomCount <= search.maxroomcount.Value);
                    }
                    result = entities.Count();

                    return(ActionResponse <int> .Succeed(result));
                }
                else
                {
                    return(ActionResponse <int> .Succeed(result));
                }
            }
            catch (Exception ex)
            {
                return(ActionResponse <int> .Failure(ex.Message));
            }
        }
        public ActionResponse <IQueryable <GenericAnnouncementDto> > SearchPagerSortBy(SearchDto search, int currentPage, int pageSize, params Enums.Status[] statuses)
        {
            try
            {
                var ctx = new MainDataContext();

                var entities = ctx.Set <GenericAnnouncementDao>()
                               .Where(e => statuses.Count() == 0 || statuses.Contains(e.Status));
                var result = entities.Select(ToDTO).AsQueryable();
                if (entities != null)
                {
                    List <string> citiNames = new List <string>();
                    //if (search.Regions.HasValue && !search.Departaments.HasValue)
                    //{

                    //    var departaments = ctx.RegionDepartaments.Where(x => x.RegionId == search.Regions.Value).ToList();
                    //    foreach (var departament in departaments)
                    //    {
                    //        var cities = ctx.DepartamentCities.Where(x => x.DepartamentId == departament.DepartamentId).ToList();
                    //        foreach (var city in cities)
                    //        {
                    //            var citiesname = ctx.Cities.Where(x => x.Id == city.CityId);
                    //            citiNames.AddRange(citiesname.Select(c => c.Name).ToList());
                    //        }
                    //    }
                    //    entities = entities.Where(x => citiNames.Contains(x.City));
                    //}
                    if (search.Departaments.HasValue)
                    {
                        var cities = ctx.DepartamentCities.Where(x => x.DepartamentId == search.Departaments.Value).ToList();
                        foreach (var city in cities)
                        {
                            var citiesname = ctx.Cities.Where(x => x.Id == city.CityId);
                            citiNames.AddRange(citiesname.Select(c => c.Name).ToList());
                        }
                        entities = entities.Where(x => citiNames.Contains(x.City));
                    }
                    if (search.Cities != null || search.CityName != null)
                    {
                        entities = entities.Where(x => search.CityName.Contains(x.City));
                    }
                    if (search.AnnouncementAdditionId != null)
                    {
                        entities = entities
                                   .Where(x => x.AnnouncementAddition.Contains(search.AnnouncementAdditionId));
                    }
                    if (search.announcementtype.HasValue)
                    {
                        entities = entities.Where(x => x.AnnouncementTypeId == search.announcementtype);
                    }
                    if (search.PropertyTypes.HasValue)
                    {
                        entities = entities.Where(x => x.PropertyTypeId == search.PropertyTypes);
                    }
                    if (search.minprice.HasValue)
                    {
                        entities = entities.Where(e => e.PriceDouble >= search.minprice.Value);
                    }
                    if (search.maxprice.HasValue)
                    {
                        entities = entities.Where(e => e.PriceDouble <= search.maxprice.Value);
                    }
                    if (search.minarea.HasValue)
                    {
                        entities = entities.Where(e => e.Area >= search.minarea.Value);
                    }
                    if (search.maxarea.HasValue)
                    {
                        entities = entities.Where(e => e.Area <= search.maxarea.Value);
                    }
                    if (search.minroomcount.HasValue)
                    {
                        entities = entities.Where(e => e.RoomCount >= search.minroomcount.Value);
                    }
                    if (search.maxroomcount.HasValue)
                    {
                        entities = entities.Where(e => e.RoomCount <= search.maxroomcount.Value);
                    }
                    if (search.sortBy.HasValue)
                    {
                        switch (search.sortBy)
                        {
                        case 1:
                            entities = entities.OrderByDescending(s => s.CreatedDate);
                            break;

                        case 2:
                            entities = entities.OrderByDescending(s => s.CreatedDate);
                            break;

                        case 3:
                            entities = entities.OrderByDescending(s => s.CreatedDate);
                            break;

                        case 4:
                            entities = entities.OrderByDescending(s => s.CreatedDate);
                            break;

                        default:
                            entities = entities.OrderByDescending(s => s.CreatedDate);
                            break;
                        }
                    }

                    else
                    {
                        entities = entities.OrderByDescending(s => s.CreatedDate);
                    }

                    result = entities.Skip((currentPage - 1) * pageSize).Take(pageSize).ToArray().Select(ToDTO).AsQueryable();

                    return(ActionResponse <IQueryable <GenericAnnouncementDto> > .Succeed(result));
                }
                else
                {
                    return(ActionResponse <IQueryable <GenericAnnouncementDto> > .Succeed(result));
                }
            }
            catch (Exception ex)
            {
                return(ActionResponse <IQueryable <GenericAnnouncementDto> > .Failure(ex.Message));
            }
        }