public ActionResponse ResetPassword(string email, string newPassword, params Status[] statuses) { try { var all = _customerRepository.GetAll(statuses); if (all.IsSucceed) { var customer = all.Data.FirstOrDefault(e => e.Email == email); if (customer != null) { customer.Password = HashHelper.ComputeHash(newPassword); return(_customerRepository.Save(customer)); } else { return(ActionResponse.Failure(UI.CustomerNotFound)); } } else { return(ActionResponse.Failure(all.FailureResult)); } } catch (Exception ex) { return(ActionResponse.Failure(ex.Message)); } }
public ActionResponse Register(CustomerDto customerDto, Guid?userId = null) { try { var customers = _customerRepository.GetAll(); if (customers.IsSucceed) { var email = customerDto.Email; var customer = customers.Data.FirstOrDefault(e => e.Email == email); if (customer != null) { return(ActionResponse <CustomerDto> .Failure(UI.EmailAlreadyExists)); } customerDto.Password = HashHelper.ComputeHash(customerDto.Password); var save = _customerRepository.Save(customerDto, userId); if (!save.IsSucceed) { return(ActionResponse <CustomerDto> .Failure(save.FailureResult)); } return(ActionResponse.Succeed()); } else { return(ActionResponse <CustomerDto> .Failure(string.Join(", ", customers.FailureResult))); } } catch (Exception ex) { return(ActionResponse <CustomerDto> .Failure(ex.Message)); } }
public async Task <ActionResponse> SignIn(string email, string password, bool rememberMe = false) { try { var user = await UserManager.FindByEmailAsync(email); var response = await SignInManager.PasswordSignInAsync(user.Email, user.PasswordHash, rememberMe, shouldLockout : false); switch (response) { case SignInStatus.Success: return(ActionResponse.Succeed()); case SignInStatus.LockedOut: return(ActionResponse.Failure($"Lockout for email {email.ToString()}")); case SignInStatus.RequiresVerification: return(ActionResponse.Failure("Sign in failed")); case SignInStatus.Failure: default: return(ActionResponse.Failure("This email or password is invalid")); } } catch (Exception exc) { return(ActionResponse <UserDto> .Failure(exc.Message)); } }
public ActionResponse Save(CustomerDto obj, Guid?userId = null) { try { if (obj.Password == null) { var c = _customerRepository.GetById(obj.Id); obj.Password = c.Data.Password; } var valResult = new CustomerValidator().Validate(obj); if (valResult.IsValid) { var customer = _customerRepository.GetById(obj.Id); obj.Email = customer.Data.Email; var response = _customerRepository.Save(obj); return(response); } else { var valErrors = valResult.Errors.Select(e => e.ErrorMessage).ToArray(); return(ActionResponse.Failure(valErrors)); } } catch (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)); } }
public ActionResponse Save(UserDto obj) { try { var dao = Mapper.Map <UserDao>(obj); if (obj.Id == default(Guid)) { var response = _userManager.Create(dao); if (!response.Succeeded) { return(ActionResponse.Failure(response.Errors.ToArray())); } var user = _userManager.FindByEmail(obj.Email); if (user == null) { return(ActionResponse.Failure($"User not found for email={obj.Email.ToString()}")); } return(ActionResponse.Succeed()); } else { using (ApplicationDataContext ctx = new ApplicationDataContext()) { ctx.Entry(dao).State = System.Data.Entity.EntityState.Modified; ctx.SaveChanges(); } return(ActionResponse.Succeed()); } } catch (Exception exc) { return(ActionResponse.Failure(exc.Message)); } }
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)); } }
public ActionResponse <UserDto> Login(string email, string password) { try { var users = _userRepository.GetAll(Status.Active); if (users.IsSucceed) { var user = users.Data.FirstOrDefault(e => e.Email == email); if (user == null) { return(ActionResponse <UserDto> .Failure(UI.UserNotFound)); } var verify = HashHelper.Verify(user.PasswordHash, password); if (!verify) { return(ActionResponse <UserDto> .Failure(UI.PasswordIsIncorrect)); } return(ActionResponse <UserDto> .Succeed(user)); } else { return(ActionResponse <UserDto> .Failure(string.Join(", ", users.FailureResult))); } } catch (Exception ex) { return(ActionResponse <UserDto> .Failure(ex.Message)); } }
public ActionResponse ResetPassword(Guid userId, string oldPassword, string newPassword, string confirmPassword, params Status[] statuses) { try { var all = _userRepository.GetAll(statuses); if (all.IsSucceed) { var user = all.Data.FirstOrDefault(e => e.Id == userId); if (user != null) { //oldPassword = user.PasswordHash; user.PasswordHash = HashHelper.ComputeHash(newPassword); return(_userRepository.Save(user)); } else { return(ActionResponse.Failure(UI.UserNotFound)); } } else { return(ActionResponse.Failure(all.FailureResult)); } } catch (Exception ex) { return(ActionResponse.Failure(ex.Message)); } }
public static ActionResponse IncomePriceSimpleItemItemAdd(DS_IncomePriceItems dS_IncomePriceItems, decimal stockId, decimal incomePriceItemId) { var dS_IncomePriseSimpleItemItems = Mapper.Map <DS_IncomePriseSimpleItemItems>(dS_IncomePriceItems); string Id = Convert.ToInt32(stockId) + "" + Convert.ToInt32(dS_IncomePriseSimpleItemItems.ID); dS_IncomePriseSimpleItemItems.ID = Convert.ToDecimal(Id); dS_IncomePriseSimpleItemItems.IdParent = incomePriceItemId; dS_IncomePriseSimpleItemItems.Moisture = 18; dS_IncomePriseSimpleItemItems.IsFirst = true; try { var ctx = new DataContext(); //var model = Mapper.Map<DS_IncomePriseSimpleItemItems>(dS_IncomePriseSimpleItemItems); using (var transaction = ctx.Database.BeginTransaction()) { ctx.Set <DS_IncomePriseSimpleItemItems>().Add(dS_IncomePriseSimpleItemItems); var result = ctx.SaveChanges(); transaction.Commit(); _logger.Info($"Save({string.Join(",", dS_IncomePriseSimpleItemItems)})"); return(ActionResponse.Succeed()); } } catch (Exception ex) { _logger.Error($"Save({string.Join(",", dS_IncomePriseSimpleItemItems)}), Exception: {ex.Message}"); return(ActionResponse.Failure(ex.Message)); } }
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)); } }
public ActionResponse DecUsedAnnouncementCount(Guid id) { try { var response = _pricePlanHistoryRepository.DecUsedAnnouncementCount(id); return(response); } catch (Exception ex) { return(ActionResponse.Failure(ex.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 <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 <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 ActionResponse Save(UserDto obj) { var result = new UserValidator().Validate(obj); if (result.IsValid) { var user = _userRepository.Save(obj); return(user); } else { var errors = result.Errors.Select(m => m.ErrorMessage).ToArray(); return(ActionResponse.Failure(errors)); } }
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 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 <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)); } }
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)); } }
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 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)); } }
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 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)); } }
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 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 Save(FrequencyDto obj, Guid?userId = null) { try { var valResult = new FrequencyValidator().Validate(obj); if (valResult.IsValid) { var response = _frequencyRepository.Save(obj); return(response); } else { var valErrors = valResult.Errors.Select(e => e.ErrorMessage).ToArray(); return(ActionResponse.Failure(valErrors)); } } catch (Exception ex) { return(ActionResponse.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)); } }