Exemplo n.º 1
0
        public HttpResponseMessage AddCard(Models.MstCard objCard)
        {
            try
            {
                var currentUser = from d in db.MstUsers where d.AspNetUserId == User.Identity.GetUserId() select d;
                if (currentUser.Any())
                {
                    if (currentUser.FirstOrDefault().UserTypeId != 3)
                    {
                        var currentCard = from d in db.MstCards where d.CardNumber.Equals(objCard.CardNumber) select d;
                        if (!currentCard.Any())
                        {
                            var motherCardUser = from d in db.MstCards where d.CardNumber.Equals(currentUser.FirstOrDefault().MotherCardNumber) select d;
                            if (motherCardUser.Any())
                            {
                                Data.MstCard newCard = new Data.MstCard
                                {
                                    CardNumber    = objCard.CardNumber,
                                    FullName      = objCard.FullName,
                                    Address       = objCard.Address,
                                    Email         = objCard.Email,
                                    ContactNumber = objCard.ContactNumber,
                                    UserId        = motherCardUser.FirstOrDefault().UserId,
                                    Balance       = 0,
                                    Particulars   = currentUser.FirstOrDefault().FullName + " " + DateTime.Now.ToString(),
                                    Status        = objCard.Status
                                };

                                db.MstCards.InsertOnSubmit(newCard);
                                db.SubmitChanges();

                                return(Request.CreateResponse(HttpStatusCode.OK));
                            }
                            else
                            {
                                return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. Mother card number was not found in the server."));
                            }
                        }
                        else
                        {
                            return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. Your card number was already taken."));
                        }
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no rights to add cards."));
                    }
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. No current user logged in."));
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Something's went wrong from the server. " + e.Message));
            }
        }
Exemplo n.º 2
0
        public HttpResponseMessage UpdateCard(String id, Models.MstCard objCard)
        {
            try
            {
                var currentUser = from d in db.MstUsers where d.AspNetUserId == User.Identity.GetUserId() select d;
                if (currentUser.Any())
                {
                    if (currentUser.FirstOrDefault().UserTypeId != 3)
                    {
                        var currentCard = from d in db.MstCards where d.Id == Convert.ToInt32(id) select d;
                        if (currentCard.Any())
                        {
                            var updateCurrentCard = currentCard.FirstOrDefault();
                            updateCurrentCard.FullName      = objCard.FullName;
                            updateCurrentCard.Address       = objCard.Address;
                            updateCurrentCard.Email         = objCard.Email;
                            updateCurrentCard.ContactNumber = objCard.ContactNumber;
                            updateCurrentCard.UserId        = currentUser.FirstOrDefault().Id;
                            updateCurrentCard.Particulars   = currentUser.FirstOrDefault().FullName + " " + DateTime.Now.ToString();
                            updateCurrentCard.Status        = objCard.Status;

                            db.SubmitChanges();

                            return(Request.CreateResponse(HttpStatusCode.OK));
                        }
                        else
                        {
                            return(Request.CreateResponse(HttpStatusCode.NotFound, "Sorry. Your card number was not found in the server."));
                        }
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no rights to update cards."));
                    }
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. No current user logged in."));
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Something's went wrong from the server. " + e.Message));
            }
        }