public JsonResult LoginAdmin()
        {
            var userName = Request.Params.Get(AppConstants.USER_NAME);
            var password = Request.Params.Get(AppConstants.PASSWORD);

            var response = new ServiceResponse();
            if(String.IsNullOrWhiteSpace(userName) || String.IsNullOrWhiteSpace(password))
            {
                response.result = ErrorConstants.REQUIRED_FIELD_EMPTY;
                return Json(response);
            }

            var cookieToken = HttpContext.Request.Cookies.Get(AppConstants.ACCESS_TOKEN);
            if(cookieToken != null)
            {
                response.result = ErrorConstants.SOMEBODY_LOGGEDIN;
                return Json(response);
            }

            try
            {
                var admin = adminManager.LoginAdmin(userName, password);
                if (admin != null)
                {
                    response.result = CookieHelper.SetSession(HttpContext, admin) ? SuccessConstants.LOGIN_SUCCESS: ErrorConstants.LOGIN_FAILED;
                    response.status = response.result == null ? false : true;
                }
                else
                    response.result = ErrorConstants.INVALID_USERNAME_OR_PASSWORD;
            }
            catch (Exception e )
            {

                Console.Error.WriteLine(e.GetBaseException().Message);
                response.result = e.GetBaseException().Message;
            }

            return Json(response);
        }
        public JsonResult AddSales()
        {
            var billNo = Request.Params.Get(AppConstants.BILL_NO);
            var dateTime = Request.Params.Get(AppConstants.DATE_TIME);
            var salesInfo = Request.Params.Get(AppConstants.SALES_INFO);
            var tax = Request.Params.Get(AppConstants.TAX);
            var discount = Request.Params.Get(AppConstants.DISCOUNT);
            var maintainStock = Request.Params.Get(AppConstants.MAINTAIN_STOCK);

            float taxFloat, discountFloat = 0;
            DateTime date;
            bool maintainStockBool;
            var response = new ServiceResponse();
            var admin = CookieHelper.GetLoggedInAdmin(HttpContext);
            if(admin == null)
            {
                response.result = ErrorConstants.ADMIN_NOT_LOGGED_IN;
                return Json(response);
            }
            if(String.IsNullOrWhiteSpace(billNo) || String.IsNullOrWhiteSpace(dateTime) || String.IsNullOrWhiteSpace(salesInfo) || String.IsNullOrWhiteSpace(tax))
            {
                response.result = ErrorConstants.REQUIRED_FIELD_EMPTY;
                return Json(response);
            }
            if(!DateTime.TryParse(dateTime, out date))
            {
                response.result = ErrorConstants.INVALID_DATA;
                return Json(response);
            }
            if(!float.TryParse(tax, out taxFloat))
            {
                response.result = ErrorConstants.INVALID_DATA;
                return Json(response);
            }
            if(!String.IsNullOrWhiteSpace(discount) && !float.TryParse(discount, out discountFloat))
            {
                response.result = ErrorConstants.INVALID_DATA;
                return Json(response);
            }
            maintainStockBool = bool.TryParse(maintainStock, out maintainStockBool) ? maintainStockBool : false;

            var sales = new List<SalesInfo>();

            try
            {
                var bill = new Sales() {
                    salesid = Guid.NewGuid(),
                    billno = billNo,
                    date = date,
                    tax = taxFloat,
                    discount = discountFloat,
                    status = (short) BillingEnums.STATUS.CLEARED,
                    created_at = DateTime.UtcNow
                    
                };
                sales = JsonConvert.DeserializeObject<List<SalesInfo>>(salesInfo);
            }
            catch (Exception e)
            {

                Console.Error.WriteLine(e.GetBaseException().Message);
                response.result = e.GetBaseException().Message;
            }

            return Json(response);
        }
Exemple #3
0
        public JsonResult UpdateUser()
        {
            var id = Request.Params.Get(AppConstants.USER_ID);
            var name = Request.Params.Get(AppConstants.NAME);
            var addr1 = Request.Params.Get(AppConstants.ADDRESS_1);
            var addr2 = Request.Params.Get(AppConstants.ADDRESS_2);
            var city = Request.Params.Get(AppConstants.CITY);
            var district = Request.Params.Get(AppConstants.DISTRICT);
            var state = Request.Params.Get(AppConstants.START);
            var country = Request.Params.Get(AppConstants.COUNTRY);
            var phone = Request.Params.Get(AppConstants.PHONE);
            var pinCode = Request.Params.Get(AppConstants.PIN_CODE);
            var email = Request.Params.Get(AppConstants.EMAIL);

            var response = new ServiceResponse();

            var admin = CookieHelper.GetLoggedInAdmin(HttpContext);
            if(admin == null)
            {
                response.result = ErrorConstants.ADMIN_NOT_LOGGED_IN;
                return Json(response);
            }
            if (String.IsNullOrWhiteSpace(id))
            {
                response.result = ErrorConstants.REQUIRED_FIELD_EMPTY;
                return Json(response);
            }
            if(String.IsNullOrWhiteSpace(name) && String.IsNullOrWhiteSpace(addr1) && String.IsNullOrWhiteSpace(addr2) && String.IsNullOrWhiteSpace(city) && String.IsNullOrWhiteSpace(district) && String.IsNullOrWhiteSpace(state) && String.IsNullOrWhiteSpace(country) && String.IsNullOrWhiteSpace(pinCode) && String.IsNullOrWhiteSpace(phone) && String.IsNullOrWhiteSpace(email))
            {
                response.result = ErrorConstants.NO_CHANGES;
                return Json(response);
            }

            try
            {
                var user = new User()
                {
                    userid = id,
                    name = name,
                    addr1 = addr1,
                    addr2 = addr2,
                    city = city,
                    district = district,
                    state = state,
                    country = country,
                    pincode = pinCode,
                    phone = phone,
                    email = email,
                };

                if (userManager.UpdateUser(admin, user))
                {
                    response.result = SuccessConstants.USER_UPDATED;
                    response.status = true;
                }
                else
                    response.result = ErrorConstants.PROBLEM_UPDATING_USER;

                return Json(response);
            }
            catch (Exception e)
            {

                Console.Error.WriteLine(e.GetBaseException().Message);
                response.result = e.GetBaseException().Message;
            }

            return Json(response);
        }
Exemple #4
0
        public JsonResult GetUsersByName()
        {
            var name = Request.Params.Get(AppConstants.NAME);
            var start = Request.Params.Get(AppConstants.START);
            var size = Request.Params.Get(AppConstants.SIZE);

            int intStart, intSize;

            var respone = new ServiceResponse();
            var admin = CookieHelper.GetLoggedInAdmin(HttpContext);
            if(admin == null)
            {
                respone.result = ErrorConstants.ADMIN_NOT_LOGGED_IN;
                return Json(respone);
            }
            if (String.IsNullOrWhiteSpace(name))
            {
                respone.result = ErrorConstants.REQUIRED_FIELD_EMPTY;
                return Json(respone);
            }

            intStart = !(String.IsNullOrWhiteSpace(start)) && int.TryParse(start, out intStart) ? Math.Max(0, intStart) : AppConstants.START_VALUE;
            intSize = !(String.IsNullOrWhiteSpace(size)) && int.TryParse(size, out intSize) ? Math.Max(0, intSize) : AppConstants.SIZE_VALUE;

            try
            {
                respone.result = userManager.GetUsersByName(admin, name, intStart, intSize);
                respone.status = true;
            }
            catch (Exception e)
            {

                Console.Error.WriteLine(e.GetBaseException().Message);
                respone.result = e.GetBaseException().Message;
            }

            return Json(respone);
        } 
Exemple #5
0
        public JsonResult GetUserById()
        {
            var id = Request.Params.Get(AppConstants.USER_ID);

            var response = new ServiceResponse();
            var admin = CookieHelper.GetLoggedInAdmin(HttpContext);
            if(admin == null)
            {
                response.result = ErrorConstants.ADMIN_NOT_LOGGED_IN;
                return Json(response);
            }
            if (String.IsNullOrWhiteSpace(id))
            {
                response.result = ErrorConstants.REQUIRED_FIELD_EMPTY;
                return Json(response);
            }

            try
            {
                var user = userManager.GetUserById(admin, id);
                if (user != null)
                {
                    response.result = user;
                    response.status = true;
                }
                else
                    response.result = ErrorConstants.USER_NOT_FOUND;

                return Json(response);
            }
            catch (Exception e)
            {

                Console.Error.WriteLine(e.GetBaseException().Message);
                response.result = e.GetBaseException().Message;
            }

            return Json(response);
        }
        public JsonResult CreateAdmin()
        {
            var userName = Request.Params.Get(AppConstants.USER_NAME);

            var response = new ServiceResponse();
            var admin = CookieHelper.GetLoggedInAdmin(HttpContext);
            if(admin == null)
            {
                response.result = ErrorConstants.ADMIN_NOT_LOGGED_IN;
                return Json(response);
            }
            if (String.IsNullOrWhiteSpace(userName))
            {
                response.result = ErrorConstants.REQUIRED_FIELD_EMPTY;
                return Json(response);
            }

            try
            {
                if (adminManager.CreateAdmin(admin, userName))
                {
                    response.result = SuccessConstants.ADMIN_CREATED;
                    response.status = true;
                }
                else
                    response.result = ErrorConstants.PROBLEM_CREATING_ADMIN;

                return Json(response);

            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.GetBaseException().Message);
                response.result = e.GetBaseException().Message;
            }

            return Json(response);
        }
        public JsonResult GetAdminList()
        {
            var response = new ServiceResponse();
            var admin = CookieHelper.GetLoggedInAdmin(HttpContext);
            if(admin == null)
            {
                response.result = ErrorConstants.ADMIN_NOT_LOGGED_IN;
                return Json(response);
            }

            try
            {
                response.result = adminManager.GetAdminList(admin);
                response.status = true;

                return Json(response);
            }
            catch (Exception e)
            {

                Console.Error.WriteLine(e.GetBaseException().Message);
                response.result = e.GetBaseException().Message;
            }

            return Json(response);

        }
        public JsonResult DeleteAdmin()
        {
            var id = Request.Params.Get(AppConstants.ID);

            Guid adminId;
            var response = new ServiceResponse();
            var admin = CookieHelper.GetLoggedInAdmin(HttpContext);
            if(admin == null)
            {
                response.result = ErrorConstants.ADMIN_NOT_LOGGED_IN;
                return Json(response);
            }
            if (String.IsNullOrWhiteSpace(id))
            {
                response.result = ErrorConstants.REQUIRED_FIELD_EMPTY;
                return Json(response);
            }
            if(!Guid.TryParse(id, out adminId))
            {
                response.result = ErrorConstants.INVALID_ID;
                return Json(response);
            }

            try
            {
                if (adminManager.DeleteAdmin(admin, adminId))
                {
                    response.result = SuccessConstants.ADMIN_DELETED;
                    response.status = true;
                }
                else
                    response.result =  ErrorConstants.PROBLEM_DELETING_AMDIN;

                return Json(response);
            }
            catch (Exception e)
            {

                Console.Error.WriteLine(e.GetBaseException().Message);
                response.result = e.GetBaseException().Message;
            }

            return Json(response);

        }
        public JsonResult ChangePassword()
        {
            var oldPassword = Request.Params.Get(AppConstants.OLD_PASSWORD);
            var newPassword = Request.Params.Get(AppConstants.NEW_PASSWORD);


            var response = new ServiceResponse();
            var admin = CookieHelper.GetLoggedInAdmin(HttpContext);
            if (admin == null)
            {
                response.result = ErrorConstants.ADMIN_NOT_LOGGED_IN;
                return Json(response);
            }
            if(String.IsNullOrWhiteSpace(oldPassword) || String.IsNullOrWhiteSpace(newPassword))
            {
                response.result = ErrorConstants.REQUIRED_FIELD_EMPTY;
                return Json(response);
            }
            if(String.Equals(oldPassword, newPassword))
            {
                response.result = ErrorConstants.NO_CHANGES;
                return Json(response);
            }
            
            try
            {
                response.result =  adminManager.ChangePassword(admin, oldPassword, newPassword) ? SuccessConstants.PASSWORD_UPDATED : ErrorConstants.PASSWORD_UPDATE_FAILED;
                response.status = true;

                return Json(response);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.GetBaseException().Message);
                response.result = e.GetBaseException().Message;
            }

            return Json(response);
        }
Exemple #10
0
        public JsonResult GenerateAdminPassword()
        {
            var id = Request.Params.Get(AppConstants.ID);

            var response = new ServiceResponse();
            var admin = CookieHelper.GetLoggedInAdmin(HttpContext);
            if(admin == null)
            {
                response.result = ErrorConstants.ADMIN_NOT_LOGGED_IN;
                return Json(response);
            }
            if (String.IsNullOrWhiteSpace(id))
            {
                response.result = ErrorConstants.REQUIRED_FIELD_EMPTY;
                return Json(response);
            }
            Guid userId;
            if(!Guid.TryParse(id, out userId))
            {
                response.result = ErrorConstants.INVALID_ID;
                return Json(response);
            }

            try
            {
                response.result = adminManager.GenerateAdminPassword(admin, userId);
                response.status = true;
                return Json(response);
            }
            catch (Exception e)
            {

                Console.Error.WriteLine(e.GetBaseException().Message);
                response.result = e.GetBaseException().Message;
            }

            return Json(response);
        }
        public JsonResult AddEmployee()
        {
            var id = Request.Params.Get(AppConstants.EMPLOYEE_ID);
            var name = Request.Params.Get(AppConstants.NAME);
            var addr1 = Request.Params.Get(AppConstants.ADDRESS_1);
            var addr2 = Request.Params.Get(AppConstants.ADDRESS_2);
            var city = Request.Params.Get(AppConstants.CITY);
            var district = Request.Params.Get(AppConstants.DISTRICT);
            var state = Request.Params.Get(AppConstants.START);
            var country = Request.Params.Get(AppConstants.COUNTRY);
            var phone = Request.Params.Get(AppConstants.PHONE);
            var pinCode = Request.Params.Get(AppConstants.PIN_CODE);
            var email = Request.Params.Get(AppConstants.EMAIL);
            var designation = Request.Params.Get(AppConstants.DESIGNATION);

            var response = new ServiceResponse();

            var admin = CookieHelper.GetLoggedInAdmin(HttpContext);
            if (admin == null)
            {
                response.result = ErrorConstants.ADMIN_NOT_LOGGED_IN;
                return Json(response);
            }
            if (String.IsNullOrWhiteSpace(id) || String.IsNullOrWhiteSpace(name))
            {
                response.result = ErrorConstants.REQUIRED_FIELD_EMPTY;
                return Json(response);
            }

            try
            {
                var employee = new Employee()
                {
                    employeeid = id,
                    name = name,
                    addr1 = addr1,
                    addr2 = addr2,
                    city = city,
                    district = district,
                    state = state,
                    country = country,
                    pincode = pinCode,
                    phone = phone,
                    email = email,
                    designation = designation,
                    created_at = DateTime.UtcNow
                };

                if (employeeManager.AddEmployee(admin, employee))
                {
                    response.result = SuccessConstants.EMPLOYEE_ADDED;
                    response.status = true;
                }
                else
                    response.result = ErrorConstants.PROBLEM_ADDING_EMPLOYEE;

                return Json(response);
            }
            catch (Exception e)
            {

                Console.Error.WriteLine(e.GetBaseException().Message);
                response.result = e.GetBaseException().Message;
            }

            return Json(response);

        }
        public JsonResult GetProductList()
        {
            var start = Request.Params.Get(AppConstants.START);
            var size = Request.Params.Get(AppConstants.SIZE);

            int intStart, intSize;

            var response = new ServiceResponse();

            var admin = CookieHelper.GetLoggedInAdmin(HttpContext);

            if(admin == null)
            {
                response.result = ErrorConstants.ADMIN_NOT_LOGGED_IN;
                return Json(response);
            }

            intStart = !String.IsNullOrWhiteSpace(start) && int.TryParse(start, out intStart) ? Math.Max(0, intStart) : AppConstants.START_VALUE;
            intSize = !String.IsNullOrWhiteSpace(size) && int.TryParse(size, out intSize) ? Math.Max(0, intSize) : AppConstants.SIZE_VALUE;

            try
            {
                response.result = productManager.GetProductList(admin, intStart, intSize);
                response.status = true;

                return Json(response);
            }
            catch (Exception e)
            {

                Console.Error.WriteLine(e.GetBaseException().Message);
                response.result = e.GetBaseException().Message;
            }

            return Json(response);
        }
        public JsonResult AddProduct()
        {
            var id = Request.Params.Get(AppConstants.PRODUCT_ID);
            var name = Request.Params.Get(AppConstants.PRODUCT_NAME);
            var price = Request.Params.Get(AppConstants.PRICE);
            var quantity = Request.Params.Get(AppConstants.QUANTITY);
            var unit = Request.Params.Get(AppConstants.UNIT);

            var response = new ServiceResponse();
            var admin = CookieHelper.GetLoggedInAdmin(HttpContext);
            if(admin == null)
            {
                response.result = ErrorConstants.ADMIN_NOT_LOGGED_IN;
                return Json(response);
            }
            if(String.IsNullOrWhiteSpace(id) || String.IsNullOrWhiteSpace(name) || String.IsNullOrWhiteSpace(price) || String.IsNullOrWhiteSpace(quantity) || String.IsNullOrWhiteSpace(unit))
            {
                response.result = ErrorConstants.REQUIRED_FIELD_EMPTY;
                return Json(response);
            }
            double priceDouble;
            float quantityFloat;
            Int16 unitInt;
            if(!Double.TryParse(price, out priceDouble) || !float.TryParse(quantity, out quantityFloat) || !Int16.TryParse(unit, out unitInt))
            {
                response.result = ErrorConstants.INVALID_DATA;
                return Json(response);
            } 

            try
            {
                var product = new Product()
                {
                    productid = id,
                    productname = name,
                    price = priceDouble,
                    quantity = quantityFloat,
                    unit = unitInt,
                    create_at = DateTime.UtcNow
                };

                if(productManager.AddProduct(admin, product))
                {
                    response.result = SuccessConstants.PRODUCT_ADDED;
                    response.status = true;
                } else
                    response.result = ErrorConstants.PROBLEM_ADDING_PRODUCT;

                return Json(response);

            }
            catch (Exception e)
            {

                Console.Error.WriteLine(e.GetBaseException().Message);
                response.result = e.GetBaseException().Message;
            }

            return Json(response);

        }