예제 #1
0
        public HttpResponseMessage putDiscount(String id, Entities.MstDiscount discount)
        {
            try
            {
                var discounts = from d in db.MstDiscounts where d.Id == Convert.ToInt32(id) select d;
                if (discounts.Any())
                {
                    //var userId = (from d in db.MstUsers where d.AspNetUserId == User.Identity.GetUserId() select d).FirstOrDefault().Id;

                    var updateDiscount = discounts.FirstOrDefault();
                    updateDiscount.Discount        = discount.Discount;
                    updateDiscount.DiscountRate    = discount.DiscountRate;
                    updateDiscount.IsVatExempt     = discount.IsVatExempt;
                    updateDiscount.DateStart       = discount.DateStart;
                    updateDiscount.DateEnd         = discount.DateEnd;
                    updateDiscount.IsTimeScheduled = discount.IsTimeScheduled;
                    updateDiscount.TimeStart       = discount.TimeStart;
                    updateDiscount.TimeEnd         = discount.TimeEnd;
                    updateDiscount.IsDayScheduled  = discount.IsDayScheduled;
                    updateDiscount.DayMon          = discount.DayMon;
                    updateDiscount.DayTue          = discount.DayTue;
                    updateDiscount.DayWed          = discount.DayWed;
                    updateDiscount.DayThu          = discount.DayThu;
                    updateDiscount.DayFri          = discount.DayFri;
                    updateDiscount.DaySat          = discount.DaySat;
                    updateDiscount.DaySun          = discount.DaySun;
                    updateDiscount.EntryUserId     = discount.EntryUserId;
                    updateDiscount.EntryDateTime   = DateTime.Now;
                    updateDiscount.UpdateUserId    = discount.UpdateUserId;
                    updateDiscount.UpdateDateTime  = DateTime.Now;
                    updateDiscount.IsLocked        = true;
                    db.SubmitChanges();

                    return(Request.CreateResponse(HttpStatusCode.OK));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound));
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }
예제 #2
0
        public Int32 postItem(Entities.MstDiscount discount)
        {
            try
            {
                var userId = (from d in db.MstUsers where d.AspNetUserId == User.Identity.GetUserId() select d).FirstOrDefault().Id;
                Data.MstDiscount newDiscount = new Data.MstDiscount();
                newDiscount.Discount        = "n/a";
                newDiscount.DiscountRate    = 0;
                newDiscount.IsVatExempt     = false;
                newDiscount.IsDateScheduled = false;
                newDiscount.DateStart       = DateTime.Today;
                newDiscount.DateEnd         = DateTime.Today;
                newDiscount.IsTimeScheduled = false;
                newDiscount.TimeStart       = DateTime.Today;
                newDiscount.TimeEnd         = DateTime.Today;
                newDiscount.IsDayScheduled  = false;
                newDiscount.DayMon          = false;
                newDiscount.DayTue          = false;
                newDiscount.DayWed          = false;
                newDiscount.DayThu          = false;
                newDiscount.DayFri          = false;
                newDiscount.DaySat          = false;
                newDiscount.DaySun          = false;
                newDiscount.EntryUserId     = userId;
                newDiscount.EntryDateTime   = DateTime.Today;
                newDiscount.UpdateUserId    = userId;
                newDiscount.UpdateDateTime  = DateTime.Today;
                newDiscount.IsLocked        = false;

                db.MstDiscounts.InsertOnSubmit(newDiscount);
                db.SubmitChanges();

                return(newDiscount.Id);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                return(0);
            }
        }
예제 #3
0
        public HttpResponseMessage AddDiscount(Entities.MstDiscount objDiscount)
        {
            try
            {
                var currentUser = from d in db.MstUsers
                                  where d.UserId == User.Identity.GetUserId()
                                  select d;

                if (currentUser.Any())
                {
                    var currentUserId = currentUser.FirstOrDefault().Id;

                    var userForms = from d in db.MstUserForms
                                    where d.UserId == currentUserId &&
                                    d.SysForm.FormName.Equals("SystemTables")
                                    select d;

                    if (userForms.Any())
                    {
                        if (userForms.FirstOrDefault().CanAdd)
                        {
                            var accounts = from d in db.MstAccounts.OrderBy(d => d.Account)
                                           where d.IsLocked == true
                                           select d;

                            if (accounts.Any())
                            {
                                Data.MstDiscount newDiscount = new Data.MstDiscount
                                {
                                    Discount        = objDiscount.Discount,
                                    DiscountRate    = objDiscount.DiscountRate,
                                    IsInclusive     = objDiscount.IsInclusive,
                                    AccountId       = objDiscount.AccountId,
                                    IsLocked        = true,
                                    CreatedById     = currentUserId,
                                    CreatedDateTime = DateTime.Now,
                                    UpdatedById     = currentUserId,
                                    UpdatedDateTime = DateTime.Now
                                };

                                db.MstDiscounts.InsertOnSubmit(newDiscount);
                                db.SubmitChanges();

                                return(Request.CreateResponse(HttpStatusCode.OK, newDiscount.Id));
                            }
                            else
                            {
                                return(Request.CreateResponse(HttpStatusCode.NotFound, "No account found. Please setup at least one account for discounts."));
                            }
                        }
                        else
                        {
                            return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no rights to add discount."));
                        }
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no access for this system table page."));
                    }
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Theres no current user logged in."));
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Something's went wrong from the server."));
            }
        }
예제 #4
0
        public HttpResponseMessage UpdateDiscount(Entities.MstDiscount objDiscount, String id)
        {
            try
            {
                var currentUser = from d in db.MstUsers
                                  where d.UserId == User.Identity.GetUserId()
                                  select d;

                if (currentUser.Any())
                {
                    var currentUserId = currentUser.FirstOrDefault().Id;

                    var userForms = from d in db.MstUserForms
                                    where d.UserId == currentUserId &&
                                    d.SysForm.FormName.Equals("SystemTables")
                                    select d;

                    if (userForms.Any())
                    {
                        if (userForms.FirstOrDefault().CanEdit)
                        {
                            var discount = from d in db.MstDiscounts
                                           where d.Id == Convert.ToInt32(id)
                                           select d;

                            if (discount.Any())
                            {
                                var updateDiscount = discount.FirstOrDefault();
                                updateDiscount.Discount        = objDiscount.Discount;
                                updateDiscount.DiscountRate    = objDiscount.DiscountRate;
                                updateDiscount.IsInclusive     = objDiscount.IsInclusive;
                                updateDiscount.AccountId       = objDiscount.AccountId;
                                updateDiscount.IsLocked        = true;
                                updateDiscount.UpdatedById     = currentUserId;
                                updateDiscount.UpdatedDateTime = DateTime.Now;

                                db.SubmitChanges();

                                return(Request.CreateResponse(HttpStatusCode.OK));
                            }
                            else
                            {
                                return(Request.CreateResponse(HttpStatusCode.NotFound, "Data not found. These discount details are not found in the server."));
                            }
                        }
                        else
                        {
                            return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no rights to edit and update discount."));
                        }
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no access for this system table page."));
                    }
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Theres no current user logged in."));
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Something's went wrong from the server."));
            }
        }