public async Task<IHttpActionResult> PutMember(int id, Member member) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != member.MemberNo) { return BadRequest(); } db.Entry(member).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MemberExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public async Task<IHttpActionResult> PostMember() { PetterResultType<Member> petterResultType = new PetterResultType<Member>(); Ciphers ciphers = new Ciphers(); List<Member> members = new List<Member>(); Member member = new Member(); if (Request.Content.IsMimeMultipartContent()) { string folder = HostingEnvironment.MapPath(UploadPath.MemberPath); Utilities.CreateDirectory(folder); var provider = await Request.Content.ReadAsMultipartAsync(); foreach (var content in provider.Contents) { string fieldName = content.Headers.ContentDisposition.Name.Trim('"'); if (!string.IsNullOrEmpty(content.Headers.ContentDisposition.FileName)) { var file = await content.ReadAsByteArrayAsync(); string fileName = Utilities.additionFileName(content.Headers.ContentDisposition.FileName.Trim('"')); if (!FileExtension.MemberExtensions.Any(x => x.Equals(Path.GetExtension(fileName.ToLower()), StringComparison.OrdinalIgnoreCase))) { petterResultType.IsSuccessful = false; petterResultType.JsonDataSet = null; petterResultType.ErrorMessage = ResultErrorMessage.FileTypeError; return Ok(petterResultType); } string fullPath = Path.Combine(folder, fileName); File.WriteAllBytes(fullPath, file); string thumbnamil = Path.GetFileNameWithoutExtension(fileName) + "_thumbnail" + Path.GetExtension(fileName); Utilities.ResizeImage(fullPath, thumbnamil, FileSize.MemberWidth, FileSize.MemberHeight, ImageFormat.Png); member.FileName = fileName; member.FilePath = UploadPath.MemberPath.Replace("~", ""); } else { string str = await content.ReadAsStringAsync(); string item = HttpUtility.UrlDecode(str); #region switch case switch (fieldName) { //case "MemberNo": // member.MemberNo = int.Parse(item); // break; case "MemberID": member.MemberID = item.ToLower(); break; case "Password": member.Password = ciphers.getCryptPassword(item); break; case "NickName": member.NickName = item; break; case "Latitude": member.Latitude = Convert.ToDouble(item); break; case "Longitude": member.Longitude = Convert.ToDouble(item); break; default: break; } #endregion switch case } } string point = string.Format("POINT({0} {1})", member.Longitude, member.Latitude); member.Coordinate = DbGeography.FromText(point); member.StateFlag = StateFlags.Use; member.Route = Route.App; member.DateCreated = DateTime.Now; member.DateModified = DateTime.Now; db.Members.Add(member); int num = await this.db.SaveChangesAsync(); members.Add(member); petterResultType.IsSuccessful = true; petterResultType.JsonDataSet = members; } else { petterResultType.IsSuccessful = false; petterResultType.JsonDataSet = null; } return Ok(petterResultType); }
public async Task<IHttpActionResult> PostMember(Member member) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Members.Add(member); await db.SaveChangesAsync(); return CreatedAtRoute("DefaultApi", new { id = member.MemberNo }, member); }