public IHttpActionResult ChangePassword(int userid, int codereset, string Newpassword) { HandelErrorObject <UsersModel> handelError = new HandelErrorObject <UsersModel>(); UsersModel user = db.Users.AsNoTracking().Where(c => c.User_ID == userid).ToList().Select(c => mf.create(c)).FirstOrDefault(); if (user != null) { if (codereset == user.Code_Reset) { user.Password = Newpassword; User u = new User() { User_ID = user.User_ID, User_Name = user.User_Name, Name = user.Name, Password = user.Password, Phone = user.Phone, Code_Reset = user.Code_Reset, Cash = user.Cash, Point = user.Point, Block = user.Block }; //db.Entry(user).State = EntityState.Detached; db.Entry(u).State = EntityState.Modified; db.SaveChanges(); handelError.data = user; handelError.status = true; handelError.message = ""; return(Ok(handelError)); } else { handelError.data = null; var message = string.Format("Code Reset is incorrect"); handelError.status = false; handelError.message = message; return(Ok(handelError)); } } else { handelError.data = null; var message = string.Format("User ID incorrect"); handelError.status = false; handelError.message = message; return(Ok(handelError)); } }
public IHttpActionResult createUser(ClientsModel clientModel) { HandelErrorObject <Client> handelError = new HandelErrorObject <Client>(); ClientsModel clientobj = db.Clients.Where(c => c.email == clientModel.email).ToList().Select(c => mf.create(c)).FirstOrDefault(); try { if (clientobj == null) { Client client = new Client(); client.Client_ID = clientModel.Client_ID; client.full_name = clientModel.full_name; client.email = clientModel.email; client.phone_number = clientModel.phone_number; client.password = clientModel.password; client.cash = clientModel.cash; client.block = clientModel.block; client.points = clientModel.points; db.Clients.Add(client); db.SaveChanges(); string Clientjson = JsonConvert.SerializeObject(client); JObject jo = JObject.Parse(Clientjson); jo.Property("password").Remove(); Client ClientCon = jo.ToObject <Client>(); handelError.data = ClientCon; handelError.status = true; handelError.message = "User created successfully"; return(Ok(handelError)); } else { handelError.data = null; handelError.status = false; handelError.message = "Email is used"; return(Ok(handelError)); } } catch (Exception e) { handelError.data = null; handelError.status = false; handelError.message = e.Message; return(Ok(handelError)); } }
public HttpResponseMessage CreateItem(ItemModel itemModel) { HandelErrorObject <Item> handelError = new HandelErrorObject <Item>(); try { Item item = new Item(); item.Item_Name = itemModel.Item_Name; item.Item_Desc = itemModel.Item_Desc; item.Item_Price = itemModel.Item_Price; item.Offer = itemModel.Offer; item.Percent = itemModel.Percent; item.Type_ID = itemModel.Type_ID; item.User_ID = itemModel.User_ID; item.Cat_ID = itemModel.Cat_ID; item.Approval = itemModel.Approval; item.Discount = itemModel.Discount; db.Items.Add(item); db.SaveChanges(); foreach (var obj in itemModel.Images.ToList()) { IR.CreateImage(obj.Image_Path, item.Item_ID); } foreach (var obj in itemModel.Genders.ToList()) { IR.CreateGender_Items(obj.Gender_ID, item.Item_ID); } handelError.data = item; handelError.status = true; handelError.message = ""; return(Request.CreateResponse(HttpStatusCode.OK, handelError)); } catch (Exception e) { handelError.data = null; handelError.status = false; handelError.message = e.Message; return(Request.CreateResponse(HttpStatusCode.NotFound, handelError)); } }