public void Delete(FarmProfile entity) { try { entities.FarmProfiles.Remove(entity); } catch (Exception ex) { throw ex; } }
public void Add(FarmProfile entity) { try { entities.FarmProfiles.Add(entity); } catch (Exception ex) { throw ex; } }
public void Attach(FarmProfile entity) { try { entities.FarmProfiles.Attach(entity); entities.Entry(entity).State = System.Data.Entity.EntityState.Modified; } catch (Exception ex) { throw ex; } }
public void Save(FarmProfile entity) { try { FarmProfile farmProfile = entities.FarmProfiles .Where(x => x.FarmID == entity.FarmID).FirstOrDefault(); if (farmProfile != null) { farmProfile = entity; entities.Entry(farmProfile).State = EntityState.Modified; } else { Add(entity); } } catch (Exception ex) { throw ex; } }
public IHttpActionResult GetFarmProfile(string MobileNo) { try { FarmProfile farmProfile = new FarmProfile(); using (UnitOfWork uow = new UnitOfWork()) { farmProfile = uow.FarmProfileRepository.Get(x => x.MobileNo == MobileNo); farmProfile = farmProfile == null ? new FarmProfile { FarmID = -1, MobileNo = MobileNo } : farmProfile; return(Ok(new { farmProfile })); } } catch (Exception ex) { throw ex; } }
public IHttpActionResult Save(FarmProfileVM farmProfileVm) { try { FarmProfile farmProfile = new FarmProfile(); using (UnitOfWork uow = new UnitOfWork()) { if (farmProfileVm.FarmID == -1) { farmProfile = new FarmProfile(); } else { farmProfile = uow.FarmProfileRepository.Get(x => x.FarmID == farmProfileVm.FarmID); } farmProfile.FarmID = farmProfileVm.FarmID; farmProfile.FarmName = farmProfileVm.FarmName; farmProfile.FarmAddress = farmProfileVm.FarmAddress; farmProfile.PhoneNo = farmProfileVm.PhoneNo; farmProfile.MobileNo = farmProfileVm.MobileNo; farmProfile.LineID = farmProfileVm.LineID; farmProfile.SocialPage = farmProfileVm.SocialPage; farmProfile.WebSite = farmProfileVm.WebSite; farmProfile.AboutUs = farmProfileVm.AboutUs; var myfilename = string.Format(@"{0}{1}", Guid.NewGuid(), ".jpeg"); if (farmProfileVm.FileName != null && farmProfileVm.FileName.Length > 0) { farmProfile.FarmLogo = myfilename; } uow.FarmProfileRepository.Save(farmProfile); uow.SaveChanges(); if (farmProfileVm.FileName != null && farmProfileVm.FileName.Length > 0) { string path = System.Web.Hosting.HostingEnvironment.MapPath("~/Uploads/" + farmProfile.FarmID + "/FarmProfile/" + farmProfile.MobileNo + "/"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string filepath = path + myfilename; var bytess = Convert.FromBase64String(farmProfileVm.FileName); using (var imageFile = new FileStream(filepath, FileMode.Create)) { imageFile.Write(bytess, 0, bytess.Length); imageFile.Flush(); } } return(Ok(farmProfile.FarmID)); } } catch (Exception ex) { throw ex; } }
public IHttpActionResult Login(User usr) { try { User user = new User(); Registration registration = new Registration(); FarmProfile farmProfile = new FarmProfile(); using (UnitOfWork uow = new UnitOfWork()) { string msg = ""; string userid = ""; int FarmID = 0; user = uow.UserRepository.Get(x => x.UserID == usr.UserID); if (user != null) { userid = usr.UserID; if (user.Password != usr.Password) { msg = "invalid password"; //return Ok(new //{ // message = msg, // userid = usr.UserID, // FarmID = 0 //}); } else { farmProfile = uow.FarmProfileRepository.Get(x => x.MobileNo == usr.UserID); if (farmProfile != null) { msg = "goto menu"; FarmID = farmProfile.FarmID; //return Ok(new //{ // message = msg, // userid = usr.UserID, // FarmID = 0 //}); } else { msg = "goto farm"; //return Ok(new //{ // message = msg, // userid = usr.UserID, // FarmID = 0 //}); } } } else { registration = uow.RegistrationRepository.Get(x => x.MobileNo == usr.UserID); if (registration != null) { userid = usr.UserID; if (registration.Password != usr.Password) { msg = "invalid password"; } else { msg = "goto otp"; } } else { msg = "goto registration"; } } return(Ok(new { message = msg, userid, FarmID })); } } catch (Exception ex) { throw ex; } }