public static OtherExpenseReportModel ToReportModel(OtherExpence model)
 {
     return(new OtherExpenseReportModel()
     {
         Name = model.Name,
         Amount = model.Amount,
         SaleId = model.SaleId.HasValue?model.SaleId.Value:0
     });
 }
Beispiel #2
0
        public ActionResult CreateEditOtherExpense(OtherExpence model)
        {
            RequestResultModel response = new RequestResultModel();

            try
            {
                if (ModelState.IsValid)
                {
                    if (model.Id > 0)
                    {
                        var toUpdate = Context.OtherExpenceRepo.GetByID(model.Id);
                        toUpdate.Name   = model.Name;
                        toUpdate.Amount = model.Amount;
                        toUpdate.SaleId = model.SaleId;

                        Context.OtherExpenceRepo.Update(toUpdate);
                        Context.Save();


                        UpdateSale(toUpdate.SaleId.Value);

                        response.Message  = GetMessage(Data.Enums.ResponseMessage.Update);
                        response.ReturnId = toUpdate.Id.ToString();
                    }
                    else
                    {
                        var toInsert = model;

                        Context.OtherExpenceRepo.Insert(toInsert);
                        Context.Save();

                        UpdateSale(toInsert.SaleId.Value);

                        response.Message  = GetMessage(Data.Enums.ResponseMessage.Save);
                        response.ReturnId = toInsert.Id.ToString();
                    }

                    return(ReturnSuccessResponse(response));
                }
                else
                {
                    response.Message = GetValidationErrors();
                }
            }
            catch (Exception e)
            {
                response.Message = GetValidationErrors();
            }

            return(ReturnErrorResponse(response));
        }
Beispiel #3
0
        public ActionResult CreateEditOtherExpense(int id = 0, int saleId = 0)
        {
            OtherExpence otherExpense;

            if (id > 0)
            {
                otherExpense = Context.OtherExpenceRepo.GetByID(id);
            }
            else
            {
                otherExpense = new OtherExpence()
                {
                    SaleId = saleId
                };
            }

            return(PartialView("_CreateEditOtherExpense", otherExpense));
        }