public List <StoreMessageTemplateObject> Search(string searchCriteria)
        {
            try
            {
                using (var db = new ShopKeeperStoreEntities())
                {
                    var templates = db.StoreMessageTemplates.Where(m => m.Subject.ToLower() == searchCriteria.ToLower().Trim()).ToList();
                    if (!templates.Any())
                    {
                        return(new List <StoreMessageTemplateObject>());
                    }
                    var newList = new List <StoreMessageTemplateObject>();
                    templates.ForEach(app =>
                    {
                        var messageTemplateObject = ModelCrossMapper.Map <StoreMessageTemplate, StoreMessageTemplateObject>(app);
                        if (messageTemplateObject != null && messageTemplateObject.EventTypeId > 0)
                        {
                            var msgEvent = Enum.GetName(typeof(MessageEventEnum), messageTemplateObject.EventTypeId);
                            if (msgEvent != null)
                            {
                                messageTemplateObject.EventTypeName = msgEvent.Replace("_", " ");
                            }

                            newList.Add(messageTemplateObject);
                        }
                    });
                    return(newList);
                }
            }
            catch (Exception ex)
            {
                return(new List <StoreMessageTemplateObject>());
            }
        }
        public long AddMessageTemplate(StoreMessageTemplateObject messageTemplate)
        {
            try
            {
                if (messageTemplate == null)
                {
                    return(-2);
                }

                var messageTemplateEntity = ModelCrossMapper.Map <StoreMessageTemplateObject, StoreMessageTemplate>(messageTemplate);

                if (messageTemplateEntity == null || messageTemplateEntity.EventTypeId < 1)
                {
                    return(-2);
                }

                using (var db = new ShopKeeperStoreEntities())
                {
                    var returnStatus = db.StoreMessageTemplates.Add(messageTemplateEntity);
                    db.SaveChanges();
                    return(returnStatus.Id);
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message);
                return(0);
            }
        }
        public StoreMessageTemplateObject GetMessageTemp(int messageEventId)
        {
            try
            {
                using (var db = new ShopKeeperStoreEntities())
                {
                    var templates = db.StoreMessageTemplates.Where(m => m.EventTypeId == messageEventId).ToList();
                    if (!templates.Any())
                    {
                        return(new StoreMessageTemplateObject());
                    }

                    var app = templates[0];

                    var messageTemplateObject = ModelCrossMapper.Map <StoreMessageTemplate, StoreMessageTemplateObject>(app);
                    if (messageTemplateObject == null || messageTemplateObject.Id < 1)
                    {
                        return(new StoreMessageTemplateObject());
                    }

                    return(messageTemplateObject);
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message);
                return(new StoreMessageTemplateObject());
            }
        }
예제 #4
0
        public long UpdateMessage(StoreMessageObject message)
        {
            try
            {
                if (message == null)
                {
                    return(-2);
                }

                using (var db = new ShopKeeperStoreEntities())
                {
                    var msgs = db.StoreMessages.Where(k => k.Id == message.Id).ToList();
                    if (!msgs.Any())
                    {
                        return(-2);
                    }
                    var msg = msgs[0];
                    msg.MessageTemplateId = message.MessageTemplateId;
                    msg.Status            = message.Status;
                    msg.DateSent          = msg.DateSent;
                    msg.MessageBody       = message.MessageBody;
                    db.Entry(msg).State   = EntityState.Modified;
                    db.SaveChanges();
                    return(msg.Id);
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message);
                return(0);
            }
        }
        public StoreMessageTemplateObject GetMessageTemplate(int messageEventId, string email)
        {
            try
            {
                using (var db = new ShopKeeperStoreEntities())
                {
                    var users = db.AspNetUsers.Where(a => a.Email == email).Include("UserProfile").ToList();
                    if (!users.Any())
                    {
                        return(new StoreMessageTemplateObject());
                    }
                    var templates = db.StoreMessageTemplates.Where(m => m.EventTypeId == messageEventId).ToList();

                    var app = templates[0];
                    var messageTemplateObject = ModelCrossMapper.Map <StoreMessageTemplate, StoreMessageTemplateObject>(app);
                    if (messageTemplateObject == null || messageTemplateObject.Id < 1)
                    {
                        return(new StoreMessageTemplateObject());
                    }
                    var userId = users[0].UserProfile.Id;
                    messageTemplateObject.UserId = userId;
                    return(messageTemplateObject);
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message);
                return(new StoreMessageTemplateObject());
            }
        }
        public long DeleteMessageTemplate(long messageTemplateId)
        {
            try
            {
                using (var db = new ShopKeeperStoreEntities())
                {
                    var myItems =
                        db.StoreMessageTemplates.Where(m => m.Id == messageTemplateId).ToList();
                    if (!myItems.Any())
                    {
                        return(0);
                    }

                    var item = myItems[0];
                    db.StoreMessageTemplates.Remove(item);
                    db.SaveChanges();
                    return(5);
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message);
                return(0);
            }
        }
        public StoreMessageTemplateObject GetMessageTemplate(long messageTemplateId)
        {
            try
            {
                using (var db = new ShopKeeperStoreEntities())
                {
                    var templates =
                        db.StoreMessageTemplates.Where(m => m.Id == messageTemplateId)
                        .ToList();
                    if (!templates.Any())
                    {
                        return(new StoreMessageTemplateObject());
                    }

                    var app = templates[0];
                    var messageTemplateObject = ModelCrossMapper.Map <StoreMessageTemplate, StoreMessageTemplateObject>(app);
                    if (messageTemplateObject == null || messageTemplateObject.Id < 1)
                    {
                        return(new StoreMessageTemplateObject());
                    }
                    var msgEvent = Enum.GetName(typeof(MessageEventEnum), messageTemplateObject.EventTypeId);
                    if (msgEvent != null)
                    {
                        messageTemplateObject.EventTypeName = msgEvent.Replace("_", " ");
                    }

                    return(messageTemplateObject);
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message);
                return(new StoreMessageTemplateObject());
            }
        }
        public long UpdateMessageTemplate(StoreMessageTemplateObject messageTemplate)
        {
            try
            {
                if (messageTemplate == null)
                {
                    return(-2);
                }

                var messageTemplateEntity = ModelCrossMapper.Map <StoreMessageTemplateObject, StoreMessageTemplate>(messageTemplate);
                if (messageTemplateEntity == null || messageTemplateEntity.Id < 1)
                {
                    return(-2);
                }

                using (var db = new ShopKeeperStoreEntities())
                {
                    db.StoreMessageTemplates.Attach(messageTemplateEntity);
                    db.Entry(messageTemplateEntity).State = EntityState.Modified;
                    db.SaveChanges();
                    return(messageTemplate.Id);
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message);
                return(0);
            }
        }
        public List <StoreMessageTemplateObject> GetMessageTemplates()
        {
            try
            {
                using (var db = new ShopKeeperStoreEntities())
                {
                    var templates = db.StoreMessageTemplates.ToList();
                    if (!templates.Any())
                    {
                        return(new List <StoreMessageTemplateObject>());
                    }
                    var objList = new List <StoreMessageTemplateObject>();
                    templates.ForEach(app =>
                    {
                        var messageTemplateObject = ModelCrossMapper.Map <StoreMessageTemplate, StoreMessageTemplateObject>(app);
                        if (messageTemplateObject != null && messageTemplateObject.Id > 0)
                        {
                            objList.Add(messageTemplateObject);
                        }
                    });

                    return(!objList.Any() ? new List <StoreMessageTemplateObject>() : objList);
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message);
                return(null);
            }
        }
예제 #10
0
        public SubscriptionRepository()
        {
            var conn = ConfigurationManager.ConnectionStrings["ShopKeeperStoreEntities"].ConnectionString;
            var shopkeeperMasterContext = new ShopKeeperStoreEntities(conn);

            _uoWork     = new UnitOfWork(shopkeeperMasterContext);
            _repository = new ShopkeeperRepository <StoreItem>(_uoWork);
        }
        public SubscriptionSettingRepository(string connectionStringSetting)
        {
            //var entityCnxStringBuilder = ConfigurationManager.ConnectionStrings["ShopKeeperStoreEntities"].ConnectionString;

            var shopkeeperMasterContext = new ShopKeeperStoreEntities(connectionStringSetting);

            _uoWork     = new UnitOfWork(shopkeeperMasterContext);
            _repository = new ShopkeeperRepository <SubscriptionSetting>(_uoWork);
        }
예제 #12
0
        public BulkCustomerRepository()
        {
            var connectionString = ConfigurationManager.ConnectionStrings["ShopKeeperStoreEntities"].ConnectionString;
            var storeSetting     = new SessionHelpers().GetStoreInfo();

            if (storeSetting != null && storeSetting.StoreId > 0)
            {
                connectionString = storeSetting.EntityConnectionString;
            }
            _db = new ShopKeeperStoreEntities(connectionString);
        }
예제 #13
0
        public List <StoreMessageObject> GetMyMessages(int?itemsPerPage, int?pageNumber, out int countG, long personId)
        {
            try
            {
                if ((itemsPerPage != null && itemsPerPage > 0) && (pageNumber != null && pageNumber >= 0))
                {
                    var tpageNumber = (int)pageNumber;
                    var tsize       = (int)itemsPerPage;

                    using (var db = new ShopKeeperStoreEntities())
                    {
                        var messages = (from msg in db.StoreMessages.Where(m => m.Id == personId).OrderByDescending(g => g.Id).Include("StoreMessageTemplate")
                                        .Skip(tpageNumber).Take(tsize)

                                        select new StoreMessageObject
                        {
                            EventTypeId = msg.StoreMessageTemplate.EventTypeId,
                            UserId = msg.UserId,
                            Id = msg.Id,
                            MessageTemplateId = msg.MessageTemplateId,
                            Status = msg.Status,
                            Subject = msg.StoreMessageTemplate.Subject,
                            MessageContent = msg.StoreMessageTemplate.MessageContent,
                            Footer = msg.StoreMessageTemplate.Footer,
                            DateSent = msg.DateSent
                        }).ToList();

                        if (messages.Any())
                        {
                            messages.ForEach(app =>
                            {
                                var msgEvent = Enum.GetName(typeof(MessageEventEnum), app.EventTypeId);
                                if (msgEvent != null)
                                {
                                    app.EventTypeName = msgEvent.Replace("_", " ");
                                }
                                app.StatusStr = Enum.GetName(typeof(MessageStatus), app.Status).Replace("_", " ");

                                app.DateSentStr = app.DateSent.ToString("dd/MM/yyyy");
                            });
                            countG = db.StoreMessages.Count(m => m.Id == personId);
                            return(messages);
                        }
                    }
                }
                countG = 0;
                return(new List <StoreMessageObject>());
            }
            catch (Exception ex)
            {
                countG = 0;
                return(new List <StoreMessageObject>());
            }
        }
예제 #14
0
       public RegisterRepository()
        {
            var connectionString = ConfigurationManager.ConnectionStrings["ShopKeeperStoreEntities"].ConnectionString;
            var storeSetting = new SessionHelpers().GetStoreInfo();
            if (storeSetting != null && storeSetting.StoreId > 0)
            {
                connectionString = storeSetting.EntityConnectionString;
            }
            var shopkeeperStoreContext = new ShopKeeperStoreEntities(connectionString); 
           _uoWork = new UnitOfWork(shopkeeperStoreContext);
           _repository = new ShopkeeperRepository<Register>(_uoWork);
		}
       public SaleTransactionRepository()
        {
            var connectionString = ConfigurationManager.ConnectionStrings["ShopKeeperStoreEntities"].ConnectionString;
            var storeSetting = new SessionHelpers().GetStoreInfo();
            if (storeSetting != null && storeSetting.StoreId > 0)
            {
                connectionString = storeSetting.EntityConnectionString;
            }
            _db = new ShopKeeperStoreEntities(connectionString);
            _uoWork = new UnitOfWork(_db);
           _repository = new ShopkeeperRepository<SaleTransaction>(_uoWork);
		}
예제 #16
0
        public long AddEmployee(EmployeeObject employee)
        {
            try
            {
                if (employee == null)
                {
                    return(-2);
                }
                using (var db = new ShopKeeperStoreEntities("name=ShopKeeperStoreEntities"))
                {
                    var duplicates = db.Employees.Count(m => m.UserProfile.LastName == employee.LastName && m.UserProfile.OtherNames == employee.OtherNames && employee.StoreOutletId == m.StoreOutletId);
                    if (duplicates > 0)
                    {
                        return(-3);
                    }

                    var employeeEntity = ModelCrossMapper.Map <EmployeeObject, Employee>(employee);
                    if (employeeEntity == null || employeeEntity.StoreDepartmentId < 1)
                    {
                        return(-2);
                    }

                    var outlets = db.StoreOutlets.ToList();
                    if (!outlets.Any())
                    {
                        return(-2);
                    }

                    employeeEntity.StoreOutletId = outlets[0].StoreOutletId;
                    var returnStatus = _repository.Add(employeeEntity);
                    _uoWork.SaveChanges();
                    return(returnStatus.EmployeeId);
                }
            }
            catch (DbEntityValidationException e)
            {
                var str = "";
                foreach (var eve in e.EntityValidationErrors)
                {
                    str += string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                         eve.Entry.Entity.GetType().Name, eve.Entry.State) + "\n";
                    foreach (var ve in eve.ValidationErrors)
                    {
                        str += string.Format("- Property: \"{0}\", Error: \"{1}\"",
                                             ve.PropertyName, ve.ErrorMessage) + " \n";
                    }
                }
                ErrorLogger.LogError(e.StackTrace, e.Source, str);
                return(0);
            }
        }
예제 #17
0
        public List <StoreMessageObject> Search(string searchCriteria)
        {
            try
            {
                using (var db = new ShopKeeperStoreEntities())
                {
                    var messages = (from msgt in db.StoreMessageTemplates.Where(u => u.Subject.ToLower().Contains(searchCriteria.ToLower()))
                                    join msg in db.StoreMessages.OrderByDescending(g => g.DateSent) on msgt.Id equals msg.MessageTemplateId
                                    join usr in db.UserProfiles.Include("AspNetUsers") on msg.Id equals usr.Id
                                    select new StoreMessageObject
                    {
                        EventTypeId = msgt.EventTypeId,
                        UserId = msg.Id,
                        Id = msg.Id,
                        MessageTemplateId = msgt.Id,
                        Status = msg.Status,
                        Receipient = usr.LastName + " " + usr.OtherNames,
                        Subject = msgt.Subject,
                        MessageContent = msgt.MessageContent,
                        Footer = msgt.Footer
                    }).ToList();

                    if (!messages.Any())
                    {
                        return(new List <StoreMessageObject>());
                    }

                    messages.ForEach(app =>
                    {
                        var msgEvent = Enum.GetName(typeof(MessageEventEnum), app.EventTypeId);
                        if (msgEvent != null)
                        {
                            app.EventTypeName = msgEvent.Replace("_", " ");
                        }
                        var status = Enum.GetName(typeof(MessageStatus), app.Status);
                        if (status != null)
                        {
                            app.EventTypeName = status.Replace("_", " ");
                        }
                    });
                    return(messages);
                }
            }
            catch (Exception ex)
            {
                return(new List <StoreMessageObject>());
            }
        }
        public List <StoreMessageTemplateObject> GetMessageTemplates(int?itemsPerPage, int?pageNumber, out int countG)
        {
            try
            {
                if ((itemsPerPage != null && itemsPerPage > 0) && (pageNumber != null && pageNumber >= 0))
                {
                    var tpageNumber = (int)pageNumber;
                    var tsize       = (int)itemsPerPage;

                    using (var db = new ShopKeeperStoreEntities())
                    {
                        var templates =
                            db.StoreMessageTemplates
                            .OrderByDescending(m => m.Id)
                            .Skip(tpageNumber).Take(tsize)
                            .ToList();
                        if (templates.Any())
                        {
                            var newList = new List <StoreMessageTemplateObject>();
                            templates.ForEach(app =>
                            {
                                var messageTemplateObject = ModelCrossMapper.Map <StoreMessageTemplate, StoreMessageTemplateObject>(app);
                                if (messageTemplateObject != null && messageTemplateObject.Id > 0)
                                {
                                    var msgEvent = Enum.GetName(typeof(MessageEventEnum), messageTemplateObject.EventTypeId);
                                    if (msgEvent != null)
                                    {
                                        messageTemplateObject.EventTypeName = msgEvent.Replace("_", " ");
                                    }

                                    newList.Add(messageTemplateObject);
                                }
                            });
                            countG = db.StoreMessageTemplates.Count();
                            return(newList);
                        }
                    }
                }
                countG = 0;
                return(new List <StoreMessageTemplateObject>());
            }
            catch (Exception ex)
            {
                countG = 0;
                return(new List <StoreMessageTemplateObject>());
            }
        }
예제 #19
0
        public List <StoreMessageObject> GetMyMessages(long personId)
        {
            try
            {
                using (var db = new ShopKeeperStoreEntities())
                {
                    var messages = (from msg in db.StoreMessages.Where(m => m.Id == personId).OrderByDescending(g => g.DateSent).Include("StoreMessageTemplate")
                                    join usr in db.UserProfiles.Include("AspNetUsers") on msg.Id equals usr.Id

                                    select new StoreMessageObject
                    {
                        EventTypeId = msg.StoreMessageTemplate.EventTypeId,
                        UserId = msg.UserId,
                        Id = msg.Id,
                        MessageTemplateId = msg.MessageTemplateId,
                        Status = msg.Status,
                        Subject = msg.StoreMessageTemplate.Subject,
                        MessageContent = msg.MessageBody,
                        Footer = msg.StoreMessageTemplate.Footer,
                        DateSent = msg.DateSent
                    }).ToList();

                    if (!messages.Any())
                    {
                        return(new List <StoreMessageObject>());
                    }
                    messages.ForEach(app =>
                    {
                        var msgEvent = Enum.GetName(typeof(MessageEventEnum), app.EventTypeId);
                        if (msgEvent != null)
                        {
                            app.EventTypeName = msgEvent.Replace("_", " ");
                        }
                        app.StatusStr = Enum.GetName(typeof(MessageStatus), app.Status).Replace("_", " ");

                        app.DateSentStr = app.DateSent.ToString("dd/MM/yyyy");
                    });
                    return(messages);
                }
            }
            catch (Exception ex)
            {
                return(new List <StoreMessageObject>());
            }
        }
예제 #20
0
        public StoreMessageObject GetMessage(long messageId)
        {
            try
            {
                using (var db = new ShopKeeperStoreEntities())
                {
                    var messages = (from msg in db.StoreMessages.Where(o => o.Id == messageId).OrderByDescending(g => g.DateSent).Include("StoreMessageTemplate")
                                    join usr in db.UserProfiles.Include("AspNetUsers") on msg.Id equals usr.Id
                                    select new StoreMessageObject
                    {
                        EventTypeId = msg.StoreMessageTemplate.EventTypeId,
                        UserId = msg.Id,
                        Id = msg.Id,
                        MessageTemplateId = msg.MessageTemplateId,
                        Status = msg.Status,
                        Subject = msg.StoreMessageTemplate.Subject,
                        MessageContent = msg.MessageBody,
                        Footer = msg.StoreMessageTemplate.Footer
                    }).ToList();

                    if (!messages.Any())
                    {
                        return(new StoreMessageObject());
                    }

                    var app      = messages[0];
                    var msgEvent = Enum.GetName(typeof(MessageEventEnum), app.EventTypeId);
                    if (msgEvent != null)
                    {
                        app.EventTypeName = msgEvent.Replace("_", " ");
                    }
                    var status = Enum.GetName(typeof(MessageStatus), app.Status);
                    if (status != null)
                    {
                        app.StatusStr = status.Replace("_", " ");
                    }
                    return(app);
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message);
                return(new StoreMessageObject());
            }
        }
        public StoreItem VerifyExistingProduct(string productNameModel, string productCode, out StoreItemStock existingStock)
        {
            try
            {
                using (var db = new ShopKeeperStoreEntities(_connectionString))
                {
                    var existingProducts = db.StoreItems.Where(m => m.Name.ToLower().Trim() == productNameModel.ToLower().Trim()).ToList();
                    if (existingProducts.Any())
                    {
                        var existingItem = existingProducts[0];
                        var stockItems   = db.StoreItemStocks.Where(s => s.StoreItemId == existingItem.StoreItemId && s.SKU.ToLower() == productCode.ToLower()).ToList();

                        if (!stockItems.Any())
                        {
                            existingStock = new StoreItemStock();
                            return(existingItem);
                        }

                        existingStock = stockItems[0];
                        return(existingItem);
                    }
                    existingStock = new StoreItemStock();
                    return(new StoreItem());
                }
            }
            catch (DbEntityValidationException e)
            {
                var str = "";
                foreach (var eve in e.EntityValidationErrors)
                {
                    str += string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                         eve.Entry.Entity.GetType().Name, eve.Entry.State) + "\n";
                    foreach (var ve in eve.ValidationErrors)
                    {
                        str += string.Format("- Property: \"{0}\", Error: \"{1}\"",
                                             ve.PropertyName, ve.ErrorMessage) + " \n";
                    }
                }

                ErrorLogger.LogError(e.StackTrace, e.Source, str);
                existingStock = new StoreItemStock();
                return(new StoreItem());
            }
        }
예제 #22
0
        public bool VerifyPhoneNumber(string phoneNumber)
        {
            try
            {
                using (var db = new ShopKeeperStoreEntities("name=ShopKeeperStoreEntities"))
                {
                    var duplicates = db.UserProfiles.Count(m => m.MobileNumber == phoneNumber);
                    if (duplicates > 0)
                    {
                        return(true);
                    }

                    return(false);
                }
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
        public int ProcessVariation(string productVariationPropStr)
        {
            try
            {
                using (var db = new ShopKeeperStoreEntities(_connectionString))
                {
                    var productVariations = db.StoreItemVariations.Where(m => m.VariationProperty.ToLower().Trim() == productVariationPropStr.ToLower().Trim()).ToList();
                    if (productVariations.Any())
                    {
                        var productVariation = productVariations[0];
                        return(productVariation.StoreItemVariationId);
                    }
                    else
                    {
                        var productVariation = new StoreItemVariation {
                            VariationProperty = productVariationPropStr.Trim()
                        };
                        var processedVariation = db.StoreItemVariations.Add(productVariation);
                        db.SaveChanges();
                        return(processedVariation.StoreItemVariationId);
                    }
                }
            }
            catch (DbEntityValidationException e)
            {
                var str = "";
                foreach (var eve in e.EntityValidationErrors)
                {
                    str += string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                         eve.Entry.Entity.GetType().Name, eve.Entry.State) + "\n";
                    foreach (var ve in eve.ValidationErrors)
                    {
                        str += string.Format("- Property: \"{0}\", Error: \"{1}\"",
                                             ve.PropertyName, ve.ErrorMessage) + " \n";
                    }
                }

                ErrorLogger.LogError(e.StackTrace, e.Source, str);
                return(-2);
            }
        }
        public UnitsOfMeasurement AddUomCode(UnitsOfMeasurement uom)
        {
            try
            {
                using (var db = new ShopKeeperStoreEntities(_connectionString))
                {
                    UnitsOfMeasurement uomInfo;
                    var uoms = db.UnitsOfMeasurements.Where(u => u.UoMCode.ToLower() == uom.UoMCode.ToLower()).ToList();
                    if (uoms.Any())
                    {
                        uomInfo = uoms[0];
                    }
                    else
                    {
                        var processeduom = db.UnitsOfMeasurements.Add(uom);
                        db.SaveChanges();
                        uomInfo = processeduom;
                    }

                    return(uomInfo);
                }
            }
            catch (DbEntityValidationException e)
            {
                var str = "";
                foreach (var eve in e.EntityValidationErrors)
                {
                    str += string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                         eve.Entry.Entity.GetType().Name, eve.Entry.State) + "\n";
                    foreach (var ve in eve.ValidationErrors)
                    {
                        str += string.Format("- Property: \"{0}\", Error: \"{1}\"",
                                             ve.PropertyName, ve.ErrorMessage) + " \n";
                    }
                }

                ErrorLogger.LogError(e.StackTrace, e.Source, str);
                return(new UnitsOfMeasurement());
            }
        }
        public StoreItemCategory ProcessCategory(StoreItemCategory category)
        {
            try
            {
                using (var db = new ShopKeeperStoreEntities(_connectionString))
                {
                    StoreItemCategory categoryInfo;
                    var categories = db.StoreItemCategories.Where(b => b.Name.Trim().ToLower().Replace(" ", "") == category.Name.Trim().ToLower().Replace(" ", "")).ToList();
                    if (!categories.Any())
                    {
                        var processedCategory = db.StoreItemCategories.Add(category);
                        db.SaveChanges();
                        categoryInfo = processedCategory;
                    }
                    else
                    {
                        categoryInfo = categories[0];
                    }

                    return(categoryInfo);
                }
            }
            catch (DbEntityValidationException e)
            {
                var str = "";
                foreach (var eve in e.EntityValidationErrors)
                {
                    str += string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                         eve.Entry.Entity.GetType().Name, eve.Entry.State) + "\n";
                    foreach (var ve in eve.ValidationErrors)
                    {
                        str += string.Format("- Property: \"{0}\", Error: \"{1}\"",
                                             ve.PropertyName, ve.ErrorMessage) + " \n";
                    }
                }

                ErrorLogger.LogError(e.StackTrace, e.Source, str);
                return(new StoreItemCategory());
            }
        }
        public StoreItemBrand AddBrand(StoreItemBrand brand)
        {
            try
            {
                using (var db = new ShopKeeperStoreEntities(_connectionString))
                {
                    StoreItemBrand brandInfo;
                    var            brands = db.StoreItemBrands.Where(b => b.Name.Trim().ToLower().Replace(" ", "") == brand.Name.Trim().ToLower().Replace(" ", "")).ToList();
                    if (!brands.Any())
                    {
                        brand.LastUpdated = DateTime.Now;
                        var processedBrand = db.StoreItemBrands.Add(brand);
                        db.SaveChanges();
                        brandInfo = processedBrand;
                    }
                    else
                    {
                        brandInfo = brands[0];
                    }
                    return(brandInfo);
                }
            }
            catch (DbEntityValidationException e)
            {
                var str = "";
                foreach (var eve in e.EntityValidationErrors)
                {
                    str += string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                         eve.Entry.Entity.GetType().Name, eve.Entry.State) + "\n";
                    foreach (var ve in eve.ValidationErrors)
                    {
                        str += string.Format("- Property: \"{0}\", Error: \"{1}\"",
                                             ve.PropertyName, ve.ErrorMessage) + " \n";
                    }
                }

                ErrorLogger.LogError(e.StackTrace, e.Source, str);
                return(new StoreItemBrand());
            }
        }
        public int GetOutlet()
        {
            try
            {
                using (var db = new ShopKeeperStoreEntities(_connectionString))
                {
                    var storeOutlets = db.StoreOutlets.ToList();
                    if (storeOutlets.Any())
                    {
                        var outletId = storeOutlets.Find(s => s.IsMainOutlet).StoreOutletId;
                        if (outletId < 1)
                        {
                            return(storeOutlets[0].StoreOutletId);
                        }

                        return(outletId);
                    }

                    return(-2);
                }
            }
            catch (DbEntityValidationException e)
            {
                var str = "";
                foreach (var eve in e.EntityValidationErrors)
                {
                    str += string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                         eve.Entry.Entity.GetType().Name, eve.Entry.State) + "\n";
                    foreach (var ve in eve.ValidationErrors)
                    {
                        str += string.Format("- Property: \"{0}\", Error: \"{1}\"",
                                             ve.PropertyName, ve.ErrorMessage) + " \n";
                    }
                }

                ErrorLogger.LogError(e.StackTrace, e.Source, str);
                return(-2);
            }
        }
예제 #28
0
 public bool UpdateProfileImage(string profileImage, long userId)
 {
     try
     {
         using (var db = new ShopKeeperStoreEntities("name=ShopKeeperStoreEntities"))
         {
             var profiles = db.UserProfiles.Where(s => s.Id == userId).ToList();
             if (!profiles.Any())
             {
                 return(false);
             }
             var profile = profiles[0];
             profile.PhotofilePath   = profileImage;
             db.Entry(profile).State = EntityState.Modified;
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message);
         return(false);
     }
 }
예제 #29
0
        public int UpdateAdmin(EmployeeObject employee)
        {
            try
            {
                if (employee == null)
                {
                    return(-2);
                }

                using (var db = new ShopKeeperStoreEntities("name=ShopKeeperStoreEntities"))
                {
                    var duplicates = db.UserProfiles.Count(m => employee.PhoneNumber == m.MobileNumber && m.Id != employee.UserId);
                    if (duplicates > 0)
                    {
                        return(-3);
                    }

                    var userprofiles = db.UserProfiles.Where(p => p.Id == employee.UserId).Include("AspNetUsers").ToList();
                    if (!userprofiles.Any())
                    {
                        return(-2);
                    }

                    var user  = userprofiles[0];
                    var users = user.AspNetUsers;
                    if (!users.Any())
                    {
                        return(-2);
                    }

                    var userInfo = users.ToList()[0];

                    userInfo.Email    = employee.Email;
                    userInfo.UserName = employee.Email;

                    user.ContactEmail = employee.Email;
                    user.MobileNumber = employee.PhoneNumber;
                    user.OtherNames   = employee.OtherNames;
                    user.LastName     = employee.LastName;
                    user.Birthday     = employee.Birthday;

                    db.Entry(user).State = EntityState.Modified;
                    db.SaveChanges();
                    db.Entry(userInfo).State = EntityState.Modified;
                    db.SaveChanges();

                    return(5);
                }
            }
            catch (DbEntityValidationException e)
            {
                var str = "";
                foreach (var eve in e.EntityValidationErrors)
                {
                    str += string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                         eve.Entry.Entity.GetType().Name, eve.Entry.State) + "\n";
                    str = eve.ValidationErrors.Aggregate(str, (current, ve) => current + (string.Format("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage) + " \n"));
                }
                ErrorLogger.LogError(e.StackTrace, e.Source, str);
                return(0);
            }
        }
예제 #30
0
        public List <StoreItemCategoryObject> GetStoreItemCategoryObjectsWithParents(int?itemsPerPage, int?pageNumber)
        {
            try
            {
                using (var db = new ShopKeeperStoreEntities(_connectionString))
                {
                    List <StoreItemCategoryObject> storeItemCategoryEntityList;
                    if ((itemsPerPage != null && itemsPerPage > 0) && (pageNumber != null && pageNumber >= 0))
                    {
                        var tpageNumber = (int)pageNumber;
                        var tsize       = (int)itemsPerPage;
                        storeItemCategoryEntityList = (from c in db.StoreItemCategories.OrderBy(m => m.StoreItemCategoryId).Skip((tpageNumber) * tsize).Take(tsize)
                                                       join x in db.StoreItemCategories on c.ParentCategoryId equals x.StoreItemCategoryId
                                                       where c.ParentCategoryId >= 0 || c.ParentCategoryId == null
                                                       select new StoreItemCategoryObject
                        {
                            Name = c.Name,
                            StoreItemCategoryId = c.StoreItemCategoryId,
                            Description = c.Description,
                            ImagePath = c.ImagePath,
                            ParentCategoryId = c.ParentCategoryId,
                            ParentCategoryObject = x == null ? new StoreItemCategoryObject() : new StoreItemCategoryObject
                            {
                                Name = x.Name,
                                StoreItemCategoryId = x.StoreItemCategoryId,
                                Description = x.Description,
                                ImagePath = x.ImagePath,
                            }
                        }).ToList();
                    }

                    else
                    {
                        storeItemCategoryEntityList = (from c in db.StoreItemCategories
                                                       join x in db.StoreItemCategories on c.ParentCategoryId equals x.StoreItemCategoryId
                                                       where c.ParentCategoryId >= 0 || c.ParentCategoryId == null
                                                       select new StoreItemCategoryObject
                        {
                            Name = c.Name,
                            StoreItemCategoryId = c.StoreItemCategoryId,
                            Description = c.Description,
                            ImagePath = c.ImagePath,
                            ParentCategoryId = c.ParentCategoryId,
                            ParentCategoryObject = x == null ? new StoreItemCategoryObject() : new StoreItemCategoryObject
                            {
                                Name = c.Name,
                                StoreItemCategoryId = c.StoreItemCategoryId,
                                Description = c.Description,
                                ImagePath = c.ImagePath,
                            }
                        }).ToList();
                    }

                    //if (!storeItemCategoryEntityList.Any())
                    //{
                    //    return new List<StoreItemCategoryObject>();
                    //}
                    //var storeItemCategoryObjList = new List<StoreItemCategoryObject>();
                    //storeItemCategoryEntityList.ForEach(m =>
                    //{
                    //    var storeItemCategoryObject = ModelCrossMapper.Map<StoreItemCategory, StoreItemCategoryObject>(m);
                    //    if (storeItemCategoryObject != null && storeItemCategoryObject.StoreItemCategoryId > 0)
                    //    {
                    //        storeItemCategoryObjList.Add(storeItemCategoryObject);
                    //    }
                    //});

                    return(storeItemCategoryEntityList ?? new List <StoreItemCategoryObject>());
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message);
                return(new List <StoreItemCategoryObject>());
            }
        }