Exemplo n.º 1
0
        public ActionResult EditEstimate(EstimateObject estimate)
        {
            var gVal = new GenericValidator();

            try
            {
                var valStatus = ValidateEstimate(estimate);
                if (valStatus.Code < 1)
                {
                    gVal.Code  = 0;
                    gVal.Error = valStatus.Error;
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                var k = new EstimateServices().UpdateEstimate(estimate);
                if (k < 1)
                {
                    gVal.Error = k == -3 ? message_Feedback.Item_Duplicate: message_Feedback.Update_Failure;
                    gVal.Code  = 0;
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                gVal.Code  = 5;
                gVal.Error = message_Feedback.Update_Success;
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
            catch
            {
                gVal.Code  = -1;
                gVal.Error = message_Feedback.Process_Failed;
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 2
0
        public ActionResult GetMyEstimates(JQueryDataTableParamModel param)
        {
            try
            {
                var userInfo = GetSignedOnUser();
                if (userInfo == null || userInfo.UserProfile.Id < 1)
                {
                    return(Json(new List <EstimateObject>(), JsonRequestBehavior.AllowGet));
                }


                IEnumerable <EstimateObject> filteredEstimateObjects;
                int countG;

                var pagedParentMenuObjects = new EstimateServices().GetEstimatesByEmployee(param.iDisplayLength, param.iDisplayStart, out countG, userInfo.UserProfile.EmployeeId);

                if (!string.IsNullOrEmpty(param.sSearch))
                {
                    filteredEstimateObjects = new EstimateServices().SearchEmployeeEstimate(param.sSearch, userInfo.UserProfile.Id);
                    countG = filteredEstimateObjects.Count();
                }
                else
                {
                    filteredEstimateObjects = pagedParentMenuObjects;
                }

                if (!filteredEstimateObjects.Any())
                {
                    return(Json(new List <EstimateObject>(), JsonRequestBehavior.AllowGet));
                }

                var sortColumnIndex = Convert.ToInt32(Request["iSortCol_0"]);
                Func <EstimateObject, string> orderingFunction = (c => sortColumnIndex == 1 ? c.CustomerName : sortColumnIndex == 2 ? c.DateCreatedStr :
                                                                  sortColumnIndex == 3 ? c.LastUpdatedStr : sortColumnIndex == 4 ? c.AmountDueStr : sortColumnIndex == 5 ? c.NetAmountStr : sortColumnIndex == 6 ? c.GeneratedByEmployee : c.InvoiceStatus);

                var sortDirection = Request["sSortDir_0"]; // asc or desc
                filteredEstimateObjects = sortDirection == "desc" ? filteredEstimateObjects.OrderBy(orderingFunction) : filteredEstimateObjects.OrderByDescending(orderingFunction);

                var displayedPersonnels = filteredEstimateObjects;

                var result = from c in displayedPersonnels
                             select new[] { Convert.ToString(c.Id), c.EstimateNumber,
                                            c.CustomerName, c.DateCreatedStr,
                                            c.AmountDueStr, c.NetAmountStr, c.GeneratedByEmployee, c.InvoiceStatus };

                return(Json(new
                {
                    param.sEcho,
                    iTotalRecords = countG,
                    iTotalDisplayRecords = countG,
                    aaData = result
                },
                            JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message);
                return(Json(new List <EstimateObject>(), JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 3
0
        public ActionResult AddEstimate(EstimateObject estimate)
        {
            var gVal = new GenericValidator();

            try
            {
                var valStatus = ValidateEstimate(estimate);
                if (valStatus.Code < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = valStatus.Error;
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                var userInfo = GetSignedOnUser();
                if (userInfo == null || userInfo.UserProfile.Id < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = "Your session has timed out.";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                estimate.ConvertedToInvoice = false;
                estimate.StoreOutletId      = userInfo.UserProfile.StoreOutletId;
                estimate.CreatedById        = userInfo.UserProfile.Id;
                estimate.OutletId           = userInfo.UserProfile.StoreOutletId;
                estimate.ContactPersonId    = userInfo.UserProfile.EmployeeId;
                estimate.DateCreated        = DateTime.Now;
                estimate.LastUpdated        = DateTime.Now;
                var  estimateNumber = "";
                long customerId;
                var  k = new EstimateServices().AddEstimate(estimate, out estimateNumber, out customerId);
                if (k < 1)
                {
                    gVal.Error = k == -3 ? message_Feedback.Item_Duplicate : message_Feedback.Insertion_Failure;
                    gVal.Code  = -1;
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                gVal.Code          = k;
                gVal.CustomerId    = customerId;
                gVal.Error         = message_Feedback.Insertion_Success;
                gVal.Date          = estimate.DateCreated.ToString("dd/MM/yyyy");
                gVal.ReferenceCode = estimateNumber;
                gVal.Time          = estimate.DateCreated.ToString("hh:mm:ss tt");
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                gVal.Code  = -1;
                gVal.Error = message_Feedback.Process_Failed;
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 4
0
 public ActionResult ConvertEstimateToInvoice(string estimateNumber)
 {
     try
     {
         var selectables = new EstimateServices().ConvertEstimateToInvoice(estimateNumber);
         return(Json(selectables, JsonRequestBehavior.AllowGet));
     }
     catch (Exception)
     {
         return(Json(new StockGenericObject(), JsonRequestBehavior.AllowGet));
     }
 }
Exemplo n.º 5
0
 public ActionResult GetEstimateInvoice(string estimateNumber)
 {
     try
     {
         if (string.IsNullOrEmpty(estimateNumber))
         {
             return(Json(new EstimateObject(), JsonRequestBehavior.AllowGet));
         }
         var estimateDetails = new EstimateServices().GetSalesDetails(estimateNumber);
         return(Json(estimateDetails, JsonRequestBehavior.AllowGet));
     }
     catch (Exception)
     {
         return(Json(new EstimateObject(), JsonRequestBehavior.AllowGet));
     }
 }
Exemplo n.º 6
0
 public ActionResult GetEstimateDetails(long id)
 {
     try
     {
         if (id < 1)
         {
             return(Json(new EstimateObject(), JsonRequestBehavior.AllowGet));
         }
         var estimateDetails = new EstimateServices().GetEstimateDetails(id);
         return(Json(estimateDetails, JsonRequestBehavior.AllowGet));
     }
     catch (Exception)
     {
         return(Json(new EstimateObject(), JsonRequestBehavior.AllowGet));
     }
 }
Exemplo n.º 7
0
        public ActionResult DeleteEstimate(long id)
        {
            var gVal = new GenericValidator();

            try
            {
                if (id < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = "Invalid selection!";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                var status = new EstimateServices().DeleteEstimate(id);
                return(Json(status, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                return(Json(new StockGenericObject(), JsonRequestBehavior.AllowGet));
            }
        }