public bool TrySetApartmentStateUnchecked(ApartmentState state) { if (this != CurrentThread) { using (LockHolder.Hold(_lock)) { if (HasStarted()) { throw new ThreadStateException(); } _initialApartmentState = state; return(true); } } if (state != ApartmentState.Unknown) { InitializeCom(state); } else { UninitializeCom(); } // Clear the cache and check whether new state matches the desired state t_apartmentType = ApartmentType.Unknown; return(state == GetApartmentState()); }
public List <ApartmentType> GetApartmentType() { List <ApartmentType> A = new List <ApartmentType>(); SqlConnection con = null; try { con = connect("DBConnectionString"); String selectSTR = "SELECT * FROM ApartmentType_2020"; SqlCommand cmd = new SqlCommand(selectSTR, con); SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); while (dr.Read()) { ApartmentType ApartmentType = new ApartmentType(); ApartmentType.Apartmenttype = (string)dr["ApartmentType"]; ApartmentType.Id = Convert.ToInt32(dr["ApartmentTypeId"]); A.Add(ApartmentType); } return(A); } catch (Exception ex) { throw (ex); } finally { if (con != null) { con.Close(); } } }
private BuildingSegment GetRandomApartment() { if (availableApartments.Count == 0) { RefreshAvailableApartments(); } int randomId = UnityEngine.Random.Range(0, availableApartments.Count); ApartmentType type = availableApartments[randomId]; availableApartments.RemoveAt(randomId); switch (type) { case ApartmentType.salon: return(ApartmentSalonSegment); case ApartmentType.kitchen: return(ApartmentKitchenSegment); case ApartmentType.bathroom: return(ApartmentBathroomSegment); default: return(null); } }
public ActionResult DeleteConfirmed(int id) { ApartmentType apartmentType = db.ApartmentTypes.Find(id); db.ApartmentTypes.Remove(apartmentType); db.SaveChanges(); return(RedirectToAction("Index")); }
// GET api/values/5 public string Get(string acName, string acAdress, ApartmentType acType) { //find by numberId = id Contact in DB. Apartment ac = new Apartment() { Id = Guid.NewGuid(), TypeId = acType, Name = acName, Address = acAdress }; repository.Create(ac); repository.Save(); var apartment = repository.GetList(); string acList = JsonConvert.SerializeObject(apartment); return acList; }
public ActionResult Edit([Bind(Include = "ApartmentTypeID,ApartmentTypeName,ApartmentTypeDescription")] ApartmentType apartmentType) { if (ModelState.IsValid) { db.Entry(apartmentType).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(apartmentType)); }
public ActionResult Edit([Bind(Include = "Id,Type")] ApartmentType apartmentType) { if (ModelState.IsValid) { db.Entry(apartmentType).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(apartmentType)); }
private bool SetApartmentStateUnchecked(ApartmentState state, bool throwOnError) { ApartmentState retState; if (this != CurrentThread) { using (LockHolder.Hold(_lock)) { if (HasStarted()) { throw new ThreadStateException(); } // Compat: Disallow resetting the initial apartment state if (_initialApartmentState == ApartmentState.Unknown) { _initialApartmentState = state; } retState = _initialApartmentState; } } else { if ((t_comState & ComState.Locked) == 0) { if (state != ApartmentState.Unknown) { InitializeCom(state); } else { UninitializeCom(); } } // Clear the cache and check whether new state matches the desired state t_apartmentType = ApartmentType.Unknown; retState = GetApartmentState(); } if (retState != state) { if (throwOnError) { string msg = SR.Format(SR.Thread_ApartmentState_ChangeFailed, retState); throw new InvalidOperationException(msg); } return(false); } return(true); }
public ActionResult Create([Bind(Include = "ApartmentTypeID,ApartmentTypeName,ApartmentTypeDescription")] ApartmentType apartmentType) { if (ModelState.IsValid) { db.ApartmentTypes.Add(apartmentType); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(apartmentType)); }
public override bool IsValid(object value) { IEnumerable <ApartmentType> listOfClients = db.ApartmentTypes; ApartmentType validatableApartmentType = value as ApartmentType; foreach (ApartmentType a in listOfClients) { if (validatableApartmentType.Type == a.Type) { return(false); } } return(true); }
// GET: ApartmentType/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ApartmentType apartmentType = db.ApartmentTypes.Find(id); if (apartmentType == null) { return(HttpNotFound()); } return(View(apartmentType)); }
public ClientWithoutSimpleFact(ApartmentType type) { if (type == ApartmentType.OneBHK) { aprtmntObj = new OneBHKApartment(); } else if (type == ApartmentType.TwoBHK) { aprtmntObj = new TwoBHKApartment(); } else { aprtmntObj = null; } }
// GET api/values/5 public string Get(string acName, string acAdress, ApartmentType acType) { //find by numberId = id Contact in DB. Apartment ac = new Apartment() { Id = Guid.NewGuid(), TypeId = acType, Name = acName, Address = acAdress }; repository.Create(ac); repository.Save(); var apartment = repository.GetList(); string acList = JsonConvert.SerializeObject(apartment); return(acList); }
public ApartmentWithSimpleFact Create(ApartmentType type) { ApartmentWithSimpleFact aprtmntObj; if (type == ApartmentType.OneBHK) { aprtmntObj = new OneBHKApartment(); } else if (type == ApartmentType.TwoBHK) { aprtmntObj = new TwoBHKApartment(); } else { aprtmntObj = null; } return(aprtmntObj); }
public ActionResult Create([Bind(Include = "Id,Type")] ApartmentType apartmentType) { foreach (ApartmentType at in db.ApartmentTypes.ToList()) { //Проверка типа апартаментов на уникальность if (apartmentType.Type == at.Type) { ModelState.AddModelError("Type", "Такой тип апартаментов уже сущесевствует"); } } if (ModelState.IsValid) { db.ApartmentTypes.Add(apartmentType); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(apartmentType)); }
public async Task <Response> Handle(CreateApartmentTypeCommand request, CancellationToken cancellationToken) { try { var dbApartmentType = await _unitOfWork.Repository <ApartmentType>().FindOne(x => x.Type == request.Type); if (dbApartmentType == null) { var apartmentType = new ApartmentType() { Type = request.Type, Description = request.Description }; _unitOfWork.Repository <ApartmentType>().Insert(apartmentType); await _unitOfWork.SaveChangeAsync(); return(await Task.FromResult(new Response { Code = ErrorCodeMessage.Success.Key, Message = ErrorCodeMessage.Success.Value, Data = _mapper.Map <ApartmentTypeDTO>(apartmentType) })); } return(await Task.FromResult(new Response { Code = ErrorCodeMessage.IdentityDuplicate.Key, Message = ErrorCodeMessage.IdentityDuplicate.Value, })); } catch (Exception ex) { throw new Exception(ex.Message, ex.InnerException); } }
public async Task <IActionResult> AddApartmentType(string name) { if (!String.IsNullOrEmpty(name)) { try { var apartmentType = new ApartmentType { Name = name, }; await _dbContext.ApartmentTypes.AddAsync(apartmentType); await _dbContext.SaveChangesAsync(); return(Json(apartmentType)); } catch (Exception) { return(Json("fail")); } } return(Json("fail")); }
internal static ApartmentType GetCurrentApartmentType() { ApartmentType currentThreadType = t_apartmentType; if (currentThreadType != ApartmentType.Unknown) { return(currentThreadType); } Interop.APTTYPE aptType; Interop.APTTYPEQUALIFIER aptTypeQualifier; int result = Interop.Ole32.CoGetApartmentType(out aptType, out aptTypeQualifier); ApartmentType type = ApartmentType.Unknown; switch (result) { case HResults.CO_E_NOTINITIALIZED: type = ApartmentType.None; break; case HResults.S_OK: switch (aptType) { case Interop.APTTYPE.APTTYPE_STA: case Interop.APTTYPE.APTTYPE_MAINSTA: type = ApartmentType.STA; break; case Interop.APTTYPE.APTTYPE_MTA: type = ApartmentType.MTA; break; case Interop.APTTYPE.APTTYPE_NA: switch (aptTypeQualifier) { case Interop.APTTYPEQUALIFIER.APTTYPEQUALIFIER_NA_ON_MTA: case Interop.APTTYPEQUALIFIER.APTTYPEQUALIFIER_NA_ON_IMPLICIT_MTA: type = ApartmentType.MTA; break; case Interop.APTTYPEQUALIFIER.APTTYPEQUALIFIER_NA_ON_STA: case Interop.APTTYPEQUALIFIER.APTTYPEQUALIFIER_NA_ON_MAINSTA: type = ApartmentType.STA; break; default: Debug.Fail("NA apartment without NA qualifier"); break; } break; } break; default: Debug.Fail("bad return from CoGetApartmentType"); break; } if (type != ApartmentType.Unknown) { t_apartmentType = type; } return(type); }
internal static ApartmentType GetCurrentApartmentType() { ApartmentType currentThreadType = t_apartmentType; if (currentThreadType != ApartmentType.Unknown) return currentThreadType; Interop._APTTYPE aptType; Interop._APTTYPEQUALIFIER aptTypeQualifier; int result = Interop.mincore.CoGetApartmentType(out aptType, out aptTypeQualifier); ApartmentType type = ApartmentType.Unknown; switch ((Interop.Constants)result) { case Interop.Constants.CoENotInitialized: type = ApartmentType.None; break; case Interop.Constants.SOk: switch (aptType) { case Interop._APTTYPE.APTTYPE_STA: case Interop._APTTYPE.APTTYPE_MAINSTA: type = ApartmentType.STA; break; case Interop._APTTYPE.APTTYPE_MTA: type = ApartmentType.MTA; break; case Interop._APTTYPE.APTTYPE_NA: switch (aptTypeQualifier) { case Interop._APTTYPEQUALIFIER.APTTYPEQUALIFIER_NA_ON_MTA: case Interop._APTTYPEQUALIFIER.APTTYPEQUALIFIER_NA_ON_IMPLICIT_MTA: type = ApartmentType.MTA; break; case Interop._APTTYPEQUALIFIER.APTTYPEQUALIFIER_NA_ON_STA: case Interop._APTTYPEQUALIFIER.APTTYPEQUALIFIER_NA_ON_MAINSTA: type = ApartmentType.STA; break; default: Contract.Assert(false, "NA apartment without NA qualifier"); break; } break; } break; default: Contract.Assert(false, "bad return from CoGetApartmentType"); break; } if (type != ApartmentType.Unknown) t_apartmentType = type; return type; }
// POST api/<controller> public void Post([FromBody] ApartmentType APT) { APT.InsertAPT(); }
// PUT api/<controller>/5 public void Put(int id, [FromBody] ApartmentType AT) { AT.UpdateAT(id); }
// GET api/<controller> public List <ApartmentType> Get() { ApartmentType A = new ApartmentType(); return(A.get()); }
internal static ApartmentType GetCurrentApartmentType() { ApartmentType currentThreadType = t_apartmentType; if (currentThreadType != ApartmentType.Unknown) { return(currentThreadType); } Interop._APTTYPE aptType; Interop._APTTYPEQUALIFIER aptTypeQualifier; int result = Interop.mincore.CoGetApartmentType(out aptType, out aptTypeQualifier); ApartmentType type = ApartmentType.Unknown; switch ((Interop.Constants)result) { case Interop.Constants.CoENotInitialized: type = ApartmentType.None; break; case Interop.Constants.SOk: switch (aptType) { case Interop._APTTYPE.APTTYPE_STA: case Interop._APTTYPE.APTTYPE_MAINSTA: type = ApartmentType.STA; break; case Interop._APTTYPE.APTTYPE_MTA: type = ApartmentType.MTA; break; case Interop._APTTYPE.APTTYPE_NA: switch (aptTypeQualifier) { case Interop._APTTYPEQUALIFIER.APTTYPEQUALIFIER_NA_ON_MTA: case Interop._APTTYPEQUALIFIER.APTTYPEQUALIFIER_NA_ON_IMPLICIT_MTA: type = ApartmentType.MTA; break; case Interop._APTTYPEQUALIFIER.APTTYPEQUALIFIER_NA_ON_STA: case Interop._APTTYPEQUALIFIER.APTTYPEQUALIFIER_NA_ON_MAINSTA: type = ApartmentType.STA; break; default: Contract.Assert(false, "NA apartment without NA qualifier"); break; } break; } break; default: Contract.Assert(false, "bad return from CoGetApartmentType"); break; } if (type != ApartmentType.Unknown) { t_apartmentType = type; } return(type); }
public ClientWithSimpleFact(ApartmentType type) { aprtmntObj.Create(type); }