Beispiel #1
0
        public HttpResponseMessage AddTaxType(Entities.MstTaxType objTaxType)
        {
            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.MstTaxType newTaxType = new Data.MstTaxType
                                {
                                    TaxType         = objTaxType.TaxType,
                                    TaxRate         = objTaxType.TaxRate,
                                    IsInclusive     = objTaxType.IsInclusive,
                                    AccountId       = objTaxType.AccountId,
                                    IsLocked        = true,
                                    CreatedById     = currentUserId,
                                    CreatedDateTime = DateTime.Now,
                                    UpdatedById     = currentUserId,
                                    UpdatedDateTime = DateTime.Now
                                };

                                db.MstTaxTypes.InsertOnSubmit(newTaxType);
                                db.SubmitChanges();

                                return(Request.CreateResponse(HttpStatusCode.OK, newTaxType.Id));
                            }
                            else
                            {
                                return(Request.CreateResponse(HttpStatusCode.NotFound, "No account found. Please setup at least one account for tax types."));
                            }
                        }
                        else
                        {
                            return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no rights to add tax type."));
                        }
                    }
                    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."));
            }
        }
Beispiel #2
0
        public HttpResponseMessage UpdateTaxType(Entities.MstTaxType objTaxType, 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 taxType = from d in db.MstTaxTypes
                                          where d.Id == Convert.ToInt32(id)
                                          select d;

                            if (taxType.Any())
                            {
                                var updateTaxType = taxType.FirstOrDefault();
                                updateTaxType.TaxType         = objTaxType.TaxType;
                                updateTaxType.TaxRate         = objTaxType.TaxRate;
                                updateTaxType.IsInclusive     = objTaxType.IsInclusive;
                                updateTaxType.AccountId       = objTaxType.AccountId;
                                updateTaxType.IsLocked        = true;
                                updateTaxType.UpdatedById     = currentUserId;
                                updateTaxType.UpdatedDateTime = DateTime.Now;

                                db.SubmitChanges();

                                return(Request.CreateResponse(HttpStatusCode.OK));
                            }
                            else
                            {
                                return(Request.CreateResponse(HttpStatusCode.NotFound, "Data not found. These tax type details are not found in the server."));
                            }
                        }
                        else
                        {
                            return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no rights to edit and update tax type."));
                        }
                    }
                    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."));
            }
        }