Ejemplo 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));
            }
        }
Ejemplo n.º 2
0
        private GenericValidator ValidateEstimate(EstimateObject estimate)
        {
            var gVal = new GenericValidator();

            if (estimate == null)
            {
                gVal.Code  = -1;
                gVal.Error = message_Feedback.Fatal_Error;
                return(gVal);
            }

            if (estimate.AmountDue < 1)
            {
                gVal.Code  = -1;
                gVal.Error = message_Feedback.Derived_Total_Cost_Error;
                return(gVal);
            }

            if (!estimate.EstimateItemObjects.Any())
            {
                gVal.Code  = -1;
                gVal.Error = message_Feedback.Estimate_Items_Error;
                return(gVal);
            }

            gVal.Code = 5;
            return(gVal);
        }
Ejemplo 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));
            }
        }
Ejemplo n.º 4
0
 public long UpdateEstimate(EstimateObject estimate)
 {
     return(_estimateRepository.UpdateEstimate(estimate));
 }
Ejemplo n.º 5
0
 public long AddEstimate(EstimateObject estimate, out string estimateNumber, out long customerId)
 {
     return(_estimateRepository.AddEstimate(estimate, out estimateNumber, out customerId));
 }